- Learning Node.js Development
- Andrew Mead
- 473字
- 2021-06-30 18:56:51
Installing the nodemon module
Now, to automatically restart our app as we make changes to a file, we have to install a command-line utility, and we'll do this using npm. To get started, we'll go to Google Chrome (or the browser you are using) and head over to https://www.npmjs.com, as we did previously in the Installing the lodash module in our app section, and the module we're looking for is called nodemon.
The nodemon will be responsible for watching our app for changes and restarting the app when those changes occur. Right here, as we see in the following screenshot, we can view the docs for nodemon as well as various other things such as current version numbers and so on:

You will also notice that it's a really popular module, with over 30,000 downloads a day. Now, this module is a little different from the one we used in the last section, that is, lodash. The lodash got installed and added into our project's package.json file as shown in the following code block:
{
"name": "notes-node",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.4"
}
}
That means it went into our node_modules folder and we were able to require it in our app.js file (refer to the previous section for more detail). Nodemon, however, works a little differently. It's a command-line utility that gets executed from the Terminal. It will be a completely new way of starting our application, and to install modules to be run from the command line, we have to tweak the install command that we used in the last section.
For now, we can start off much the same way, though. We'll use npm install and type the name just like we did in the Installing the lodash module in our app section, but instead of using the save flag, we'll use the g flag, which is short for global, as shown here:
npm install nodemon -g
This command installs nodemon as a global utility on your machine, which means it'll not get added to your specific project and you'll never require nodemon. Instead, you'll be running the nodemon command from Terminal, as shown here:

When we install nodemon using the preceding command, it'll go off to npm and fetch all of the code that comes with nodemon.
And it'll add it into the installation where Node and npm live on your machine, outside the project you're working on.
The npm install nodemon -g command could be executed from anywhere in your machine; it does not need to be executed from the project folder since it doesn't actually update the project at all. With this in place, though, we now have a brand new command on our machine, nodemon.
- 物聯網智慧安監技術
- Hands-On Industrial Internet of Things
- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- Hands-On Chatbots and Conversational UI Development
- Spring Cloud微服務架構進階
- 中小型局域網組建、管理與維護實戰
- 物聯網通信技術
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- 語音信號處理及Blackfin DSP實現
- Microsoft Power Platform Enterprise Architecture
- Web用戶查詢日志挖掘與應用
- 人際網絡
- SEO攻略:搜索引擎優化策略與實戰案例詳解
- Python Web Scraping Cookbook
- 結網@改變世界的互聯網產品經理(修訂版)