How can I add live-reload to my nodejs server

2020-02-04 20:30发布

This is how can i run my server nodejs , i need to liverealord my server when i make changes to the code in the front-end dev

"start": "node server.js"

7条回答
叼着烟拽天下
2楼-- · 2020-02-04 21:08

You can use nodemon.
It will watch your project's files and restarts the server when you change them.

You can install it globally:

npm install -g nodemon

the run it on your projects directory

cd ./my-project
nodemon

You can also add it to your project's dev dependencies and use it from an npm script:

npm install --save-dev nodemon

Then add a simple script to your package.json:

"scripts": {
    "start": "node server.js",
    "dev": "nodemon"
}

then you can simply run the following command:

npm run dev
查看更多
登录 后发表回答