Prosty skrypt wygląda tak:
Kod
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, "127.0.0.1");
sys.puts('Server running at http://127.0.0.1/');
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, "127.0.0.1");
sys.puts('Server running at http://127.0.0.1/');
Potem uruchamia się go tak:
Kod
# node skrypt.js
Server running at http://127.0.0.1/
Server running at http://127.0.0.1/
Powstało również wiele użytecznych modułów do Node JS, np. do łączenia z bazami danych.