node启动web服务

安装好node之后

npm init -y

新建一个js文件demo.js,编写启动服务代码

const http=require('http');
const server=http.createServer((req,res)=>{
    res.end("hello word111333")
})

server.listen(3000,'127.0.0.1',()=>{
    console.log("服务启动成功")
})

然后在终端输入启动命令

node demo.js

启动成功在浏览器输入http://localhost:3000即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章