Nodejs 简单的web服务器

创建myserver.js文件:

myserver.js:

const http = require('http');

const hostname = '127.0.0.1';

const port = 3000;

const server = http.createServer((req,res) => {

res.statusCode = 200;

res.setHeader('Content-Type','text/plain');

res.end('Hello Node.js World.\n');

});

server.listen(port,hostname, () => {

console.log('Server running at http://${hostname}:${port}/');

});

打开浏览器输入:http://127.0.0.1:3000/

页面内容:

Hello Node.js World.

猜你喜欢

转载自blog.csdn.net/xlh006/article/details/83687663