1、控制台版 Hello World
编辑文件hello_world.js
var sys = require("util"); sys.puts("Hello world");
执行:node hello_world.js
结果:
2、网页版Hello world
编译文件 http_hello_world.js
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World - Node.js Work. '); }).listen(5656, '127.0.0.1'); console.log('Server running at http://127.0.0.1:5656/');执行: node http_hello_world.js
结果: