1-1 配置项目
cnpm init -y //自动生成package.json文件cnpm i nodemon -S //安装nodemon
1-2 配置package.json文件
{
"scripts":{
"start":"nodemon index.js"
}
}
1-3 启动项目
cnpm start
1-4 原生http模块启动服务
const http = require("http");
http.createServer(function(req,res){
res.end("hello world")
}).listen(8000);
1-5 koa启动服务
koa.js node.js
jquery javascript
安装koa
cnpm i koa -S
const koa = require("koa");
const app = new koa();
// ctx上下文 包含req,res
app.use(async ctx=>{
// ctx.body 给前台返回的内容
ctx.body = {
code:200,
msg:"返回成功"
}
})
app.listen(4000);