大家好呀,很久没有见啦,我的博客也写得少啦我也不够努力啦
一寸光阴一寸金,我们一起加油,不断进步呀
第一步
mkdir douban-trailer-imooc
cd douban-trailer-imooc
第二步跟我一起在git中输入
npm init
记得比较重要的地方是
entry point: (index.js) server/index.js
第三步
mkdir server
cd server
touch index.js
//server/index.js
const Koa = require('koa')
const app = new Koa()
app.use(async(ctx,next)=>{
ctx.body = '电影首页'
})
app.listen(4455)
接下来安装koa
npm install koa@latest -S
本来可以使用node server/index.js运行项目 但是是很长的一串,我们可以在package.json中修改命令
//package.json
{
"name": "douban-trailer-imooc",
"version": "1.0.0",
"description": "",
"main": "server/inder.js",
"scripts": {
"start": "node server/index.js",
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [
"movie",
"trailer"
],
"author": "dimple",
"license": "ISC",
"dependencies": {
"koa": "^2.11.0"
}
}
运行
npm start