码迷,mamicode.com
首页 > 其他好文 > 详细

2.6毕设

时间:2020-02-06 20:18:24      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:str   ext   lan   ref   使用   毕设   create   header   lis   

例子,一个使用 Node.js 编写的 web服务器,响应返回 ‘Hello World‘

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 World\n);
});

server.listen(port, hostname, () => {
  console.log(`服务器运行在 http://${hostname}:${port}/`);
});

要运行这个服务器,需将代码保存到一个名为 example.js 的文件,并使用 Node.js 执行:

$ node example.js
服务器运行在 http://127.0.0.1:3000/

2.6毕设

标签:str   ext   lan   ref   使用   毕设   create   header   lis   

原文地址:https://www.cnblogs.com/maxin123/p/12269777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!