nodejs第一个练习:用Node.js建HTTP服务器
这是官方的一个例子,
在F盘建立一个tinyphp.js文件,内容:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
在F盘下运行node tinyphp.js
然后打开浏览器访问: http://127.0.0.1:1337
需要提示的是,命令完,需要按Ctrl+C才能重新写命令的
本文来自博客园,作者:tinyphp,转载请注明原文链接:https://www.cnblogs.com/tinyphp/p/4921902.html
向着星辰与深渊,博客园加油