1.建一个app.js文件
const http = require('http'); const chalk = require('chalk'); const conf = require('./config/defaultConfig') const server = http.createServer((req,res)=>{ res.statusCode = 200; res.setHeader('Content-Type','text-plain'); res.end("hello http!") }) server.listen(conf.port,conf.hostsname,()=>{ //conf.port:3000(端口号,随便写) conf.hostname:127.0.0.1 const addr = `http://${conf.hostname}:${conf.port}`; console.info(`Server started at ${chalk.green(addr)}`) })
2.这时终端node app.js,启动服务就可以。但每次修改不能热更新,我们可以安装一个supervise在全局
3.这时不需要使用node app.js启动,可以使用supervisor app.js启动
npm i -g supervise