官术网_书友最值得收藏!

The node_modules folder

Now that you know how to use a third-party module, there is one more thing I want to discuss. That is the node_modules folder in general. When you take your Node project and you put it on GitHub, or you're copying it around or sending it to a friend, the node_modules folder really shouldn't be taken with you.

The node_modules folder contains generated code. This is not code you've written and you should never make any updates to the files inside Node modules because there's a pretty good chance they'll get overwritten next time you install some modules.

In our case, we've already defined the modules and the versions inside package.json as shown in the following code because we used that handy save flag:

{
"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"
}
}

This actually means we can delete the node_modules folder completely. Now, we can copy the folder and give it to a friend, we can put it on GitHub, or whatever we want to do. When we want to get that node_modules folder back, all we have to do inside the Terminal is run the npm install command without any module names or any flags.

This command, when run without any names or flags, is going to load in your package.json file, grab all of the dependencies and install them. After running this command, the node_modules folder is going to look exactly as it looked before we deleted it. Now, when you are using Git and GitHub, instead of deleting the node_modules folder, you'll just ignore it from your repository.

Now, what we have explored so far is a process we'll be going through a lot more throughout the book. So if npm still seems foreign or you're not quite sure why it's even useful, it will become clear as we do more with our third-party modules, rather than just type checking or looking for unique items in an array. There's a ton of power behind the npm community and we'll be harnessing that to our fullest as we make real-world apps.

主站蜘蛛池模板: 新蔡县| 澄江县| 兴和县| 静海县| 长乐市| 建瓯市| 安徽省| 洮南市| 桓仁| 临沧市| 陕西省| 鲁甸县| 凉城县| 炎陵县| 双辽市| 石景山区| 江津市| 霍林郭勒市| 五莲县| 视频| 玉林市| 新河县| 象州县| 朔州市| 浑源县| 莒南县| 周口市| 安宁市| 苗栗县| 奉新县| 鄄城县| 合川市| 久治县| 黄山市| 无为县| 永嘉县| 牡丹江市| 丰城市| 嘉善县| 儋州市| 阳山县|