Book connected back to battle on the top of Koa – 1 】 【 take three minutes to build a simple Koa service, we set up a foundation of Koa after application, want to preview, after modify the code will need to restart the project, it doesn’t accord with our efficient, developers, and a new era that we have to transform it, make it as the React or Vue as real-time thermal load, Vertical enjoy silky!

Life is limited, so don't waste it rebooting projects! -- Von Yisho

A, nodemon

Website:nodemon.io/

As you can see, the website says it will monitor your code and automatically restart the project.

Second, the integration

npm install -g nodemon
Copy the code

Three, test,

nodemon app
Copy the code

4. Configure package to run scripts quickly and ignore files

1. Run the script quickly

// Run the NPM run dev commandCopy the code

2. Configure files

Nodemon listens to files that are ignored by git.

{
  "watch": ["src"]."ext": "ts"."env": {
    "NODE_ENV": "development"
  },
  "ignore": [
    ".git"."node_modules/**/node_modules"],}Copy the code

The instructions are as follows:

Parameter names role
ignore Ignored files or folders
watch The directory or file to listen to
ext Name extension of the monitored file
env Environment variable setting
watch The directory or file to listen to

Visit the following links for more configuration

Making configuration

Five, this Demo source address

GitHub

Six, reference

1. Nodemon website

2. Nodemon Bug discussion area

Write your first Koa middleware