- 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.
- 計(jì)算機(jī)網(wǎng)絡(luò)與通信(第2版)
- 從區(qū)塊鏈到Web3:構(gòu)建未來互聯(lián)網(wǎng)生態(tài)
- Drush User’s Guide
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- PLC、現(xiàn)場(chǎng)總線及工業(yè)網(wǎng)絡(luò)實(shí)用技術(shù)速成
- 物聯(lián)網(wǎng)通信技術(shù)
- 異構(gòu)蜂窩網(wǎng)絡(luò)關(guān)鍵理論與技術(shù)
- 物聯(lián)網(wǎng),So Easy!
- Cisco無(wú)線局域網(wǎng)配置基礎(chǔ)
- Python Web Scraping Cookbook
- 智能物聯(lián)安防視頻技術(shù)基礎(chǔ)與應(yīng)用
- 巧學(xué)活用CISCO網(wǎng)絡(luò)典型配置
- 5G低功耗蜂窩物聯(lián)網(wǎng)開發(fā)與應(yīng)用
- 一本書讀懂24種互聯(lián)網(wǎng)思維
- 夢(mèng)工廠之沸騰關(guān)鍵幀:Maya動(dòng)畫手冊(cè)