Langkah pertama adalah download dulu nodejs di http://nodejs.org/download/. Saya menggunakan windows 7 Professional 64bit, jadi saya download windows installer 64-bit. Jalankan installernya kemudian ikuti instruksi selanjutnya, standar install program di windows lah.
Setelah instalasi, jalankan node.js command prompt. Saya buat sebuah file bernama hello.js, saya simpan di C:/xampp/htdocs/node. Isi filenya sebagai berikut:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Hello world!'); |
Sekarang buat file hellosvr.js, isinya sebagai berikut:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World!\n'); | |
}).listen(1337, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:1337/'); |
Tampilan node cmd prompt |
Tampilan di browser |
Demikian artikel awal node.js kali ini, semoga sahabat phpmahir bisa semakin mengerti.
Tidak ada komentar:
Posting Komentar
Jika Anda memiliki tanggapan dan pertanyaan silakan isi form komentar berikut, kami akan menjawabnya segera. :)