function main() { console.log("Hello world!"); } main();
var http = require("http"); http.createServer( function(req, res) { res.writeHead(200,{"Content_type":"text/html"}); res.write("<h1>Node.js<h1>"); res.write("<p>Hello World</p>"); }).listen(8000); console.log("HTTP server is listening at port 8000.");
运行main.js,打开浏览器输入:http://127.0.0.1:800/可以看到:
原文地址:http://blog.csdn.net/xufeng0991/article/details/44313509