nodejs http服务

创建server.js文件(最好保存为utf-8格式,这样避免中文乱码)

 

var http = require('http');
var port = 1337;
var httpServer = http.createServer(onRequest).listen(port);

function onRequest(req, res) {
	res.writeHead(200, {"Content-Type": "text/plain"});
	res.write("Hello World 你好",'utf8');
	res.end();
}

console.info('Server running at http://127.0.0.1:1337/');

 

输入命令:node workspace/server.js


nodejs http服务

在浏览器输入http://localhost:1337/


nodejs http服务

你可能感兴趣的:(nodejs)