<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Node.js - hknsoft</title>
	<atom:link href="https://hknsoft.com/kategori/node-js/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Android, Yazılım, Script</description>
	<lastBuildDate>Sat, 21 Oct 2023 09:07:33 +0000</lastBuildDate>
	<language>tr</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://hknsoft.com/wp-content/uploads/2020/05/cropped-icon-hknsoft-150x150.png</url>
	<title>Node.js - hknsoft</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Node.js Listener Kullanımı</title>
		<link>https://hknsoft.com/node-js-listener-kullanimi/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 28 May 2023 22:57:04 +0000</pubDate>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[javascript listener]]></category>
		<category><![CDATA[node.js listener]]></category>
		<category><![CDATA[node.js listener callback]]></category>
		<category><![CDATA[node.js listener kullanımı]]></category>
		<guid isPermaLink="false">https://hknsoft.com/?p=1305</guid>

					<description><![CDATA[<p>Oluşturduğumuz nesne içerisindeki olayları takip edebilmek için listenerlara ihtiyaç duyuyoruz. Örneğin, nesne içerisinde bir interval tanımladınız. Saniyede bir bu interval içindeki kod çalışıyor. Buraya kadar <a class="mh-excerpt-more" href="https://hknsoft.com/node-js-listener-kullanimi/" title="Node.js Listener Kullanımı">[...]</a></p>
<p>The post <a href="https://hknsoft.com/node-js-listener-kullanimi/">Node.js Listener Kullanımı</a> appeared first on <a href="https://hknsoft.com">hknsoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Oluşturduğumuz nesne içerisindeki olayları takip edebilmek için listenerlara ihtiyaç duyuyoruz.</p>



<p>Örneğin, nesne içerisinde bir interval tanımladınız. Saniyede bir bu interval içindeki kod çalışıyor. Buraya kadar bir sorun yok. Fakat bu interval içerisinde <strong>dışarıdan bir kod çalıştırmak</strong> istiyorsunuz. İşte bunu yapabilmek için listener kullanmalıyız.</p>



<h2 class="wp-block-heading">Class Oluşturma</h2>



<p>Öncelikle <strong>game.model.js</strong> adında bir dosya oluşturuyoruz.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">class Game {
    // bu classtan bir nesne oluşturulduğu zaman listener varsayılan olarak null tanımlanıyor
    onTick = null;

    constructor(id, players, time) {
        this.id = id;
        this.players = players;
        this.time = time;
    }

    // oyunu başlatıyoruz
    start() {
        var interval = setInterval(() =&gt; {
            if (this.time &gt; 0) {
                this.time -= 1;
            }

            // burada listenerı tetikliyoruz
            // her bir saniyede bu listener tetiklenecek
            if (this.onTick != null) this.onTick();
        }, 1000);
    }

    // dışarıdan bu fonksiyonu kullanarak listener oluşturuyoruz
    setOnTickListener(l) {
        // bu kontrolü listener birden fazla kere tanımlanmasın diye koyuyoruz
        if (this.onTick != null) return;
        this.onTick = l;
    }
}

module.exports = Game;</pre></div>



<p><strong>setOnTickListener()</strong> fonksiyonu ile dışarıdan listener tanımlaması yapabileceğiz.</p>



<h2 class="wp-block-heading">Listener Kullanımı</h2>



<p><strong>app.js</strong> dosyasında öncelikle bir Game nesnesi oluşturuyoruz. Daha sonra aşağıda gördüğünüz gibi listener tanımlaması yapıyoruz.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">// game.model.js dosyamızı çağırıyoruz
const Game = require('./game.model.js');

// yeni bir nesne oluşturuyoruz
var game = new Game('18815616', null, 30);

// bu nesneye özel bir listener oluşturuyoruz
game.setOnTickListener(() =&gt; {
    console.log('game time: ' + game.time);
});

game.start();</pre></div>



<p>Artık interval içerisinde dışarıdan (farklı bir dosyadan) kodlar çalıştırabiliriz.</p>



<p>app.js dosyasını çalıştırdığımız zaman <strong>konsolda</strong> aşağıdaki gibi bir çıktıyla karşılaşacağız.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">game time: 29
game time: 28
game time: 27
game time: 26
game time: 25
game time: 24
game time: 23
game time: 22
game time: 21</pre></div>



<h2 class="wp-block-heading has-text-align-center"><a href="https://gist.github.com/fovelas/40890a6eb6fa257bc94e6d01d22b35cb" target="_blank" rel="noreferrer noopener nofollow"><strong>GitHub</strong></a></h2>
<p>The post <a href="https://hknsoft.com/node-js-listener-kullanimi/">Node.js Listener Kullanımı</a> appeared first on <a href="https://hknsoft.com">hknsoft</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Node.js ile MySQL Bağlantısı</title>
		<link>https://hknsoft.com/node-js-ile-mysql-baglantisi/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 28 May 2023 14:19:00 +0000</pubDate>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[node js ile mysql veritabanına bağlanma]]></category>
		<category><![CDATA[node.js ile mysql]]></category>
		<category><![CDATA[node.js ile mysql bağlantısı]]></category>
		<category><![CDATA[node.js mysql sorgu çalıştırma]]></category>
		<guid isPermaLink="false">https://hknsoft.com/?p=1287</guid>

					<description><![CDATA[<p>Node.js ile MySQL bağlantısı yapabilmek için öncelikle projemize mysql kütüphanesini eklemeliyiz. Artık MySQL bağlantısı kurabiliriz. Not: Kod yazmaya başlamadan önce makinanızda MySQL&#8217;i çalıştırın. XAMPP ya <a class="mh-excerpt-more" href="https://hknsoft.com/node-js-ile-mysql-baglantisi/" title="Node.js ile MySQL Bağlantısı">[...]</a></p>
<p>The post <a href="https://hknsoft.com/node-js-ile-mysql-baglantisi/">Node.js ile MySQL Bağlantısı</a> appeared first on <a href="https://hknsoft.com">hknsoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Node.js ile MySQL bağlantısı yapabilmek için öncelikle projemize <a href="https://www.npmjs.com/package/mysql" target="_blank" rel="noreferrer noopener nofollow" class="broken_link"><strong>mysql</strong></a> kütüphanesini eklemeliyiz.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">npm install mysql</pre></div>



<p>Artık MySQL bağlantısı kurabiliriz.</p>



<p><strong>Not:</strong> Kod yazmaya başlamadan önce makinanızda MySQL&#8217;i çalıştırın. <a href="https://www.apachefriends.org/tr/index.html" target="_blank" rel="noreferrer noopener nofollow"><strong>XAMPP</strong></a> ya da WAMPP gibi yazılımları kullanabilirsiniz.</p>



<h2 class="wp-block-heading">Bağlantı Oluşturma</h2>



<p><strong>database.js</strong> adında bir dosya oluşturuyoruz.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">const mysql = require('mysql');

// database ayarları
const db = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'password',
    database: 'database_name'
});

// yukarıdaki bilgilere göre database bağlanıyoruz
db.connect(function (err) {
    // eğer bir hata oluşursa programı durdurup hatayı konsola yazdıracak
    if (err) throw err;

    // başarılı bir şekilde bağlandığını konsola yazdırıyoruz
    console.log('connection successful');
});

// db objesini export ediyoruz ki bu dosyayı çağırdığımız yerde sorgular çalıştırabilelim
module.exports = db;</pre></div>



<h2 class="wp-block-heading">Sorgu Çalıştırma</h2>



<p>Yukarıda oluşturduğumuz <strong>database.js</strong> dosyasını projemizin istediğimiz yerinde <strong>çağırarak</strong> sorgular çalıştırabiliriz.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">// database dosyamızı çağırıyoruz
const db = require('./database.js');

// sorgu çalıştırıyoruz
db.query(`SELECT * FROM players WHERE id = '107861148515'`, (err, result) =&gt; {
    if (err) throw err;
    var row = result[0];

    if (result.length &gt; 0) {
        console.log(row);
    } else {
        console.log('player not found');
    }
});</pre></div>



<h2 class="wp-block-heading has-text-align-center"><a href="https://gist.github.com/fovelas/a50848c2bb2d0ddaeead94d3e43f74f3" target="_blank" rel="noreferrer noopener nofollow"><strong>GitHub</strong></a></h2>
<p>The post <a href="https://hknsoft.com/node-js-ile-mysql-baglantisi/">Node.js ile MySQL Bağlantısı</a> appeared first on <a href="https://hknsoft.com">hknsoft</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
