Node.js之HelloWorld!

源码示例(设文件保存为hello.js):

var http = require('http');
http.createServer(function (req, res) {
	res.writeHead(200, {'Content-Type': 'text/plain'});
	res.end('Hello World!\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

打开cmd,进入文件保存目录,命令行输入node hello.js按回车从而运行程序。

打开浏览器,在地址栏输入127.0.0.1:8124则可以看到页面上输出

Hello World!

猜你喜欢

转载自blog.csdn.net/lianfengzhidie/article/details/80961846