1.新建一个app.js文件
2.使用npm install http 导入http模块
3.直接上代码
//引入http模块var http = require(‘http‘);//创建服务器var app=http.createServer(function (request, response) { ???// 发送 HTTP 头部 ????// HTTP 状态值: 200 : OK ???// 内容类型: text/plain ???response.writeHead(200, {‘Content-Type‘: ‘text/plain‘}); ???// 发送响应数据 "Hello Node.js" ???response.end(‘Hello Node.js‘); })
//添加监听,监听端口3000app.listen(‘3000‘,()=>{console.info("创建服务器成功,端口号:3000")})
【Node.js】 初体验
原文地址:https://www.cnblogs.com/qiuym/p/8984278.html