koa代码
const Koa = require('koa')
const app = new Koa()
app.use(ctx => {
ctx.body = 'hello world'
})
const port = 3000
app.listen(port) && console.log(`listening on port: ${port}`)
常规启动
node app.js
安装gulp, gulp-nodemon
npm install gulp -g
npm install gulp-nodemon --save
配置gulp
- 新建文件gulpfile.js
vi gulpfile.js
- 填入下面内容
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
gulp.task('default', () => {
nodemon({
script: 'index.js',
ext: 'js html css',
env: {
'NODE_ENV': 'development'
}
})
})
- 修改npm-script
在package.json-scripts字段加入"start": "gulp"
- 运行命令
gulp
- enjoy