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

  • Learning Node.js Development
  • Andrew Mead
  • 369字
  • 2021-06-30 18:56:51

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.

主站蜘蛛池模板: 义马市| 呼玛县| 乐陵市| 雷山县| 长泰县| 万载县| 巴中市| 商南县| 石河子市| 武宣县| 保山市| 琼海市| 东平县| 库伦旗| 阿拉尔市| 雷山县| 资溪县| 镇沅| 镇平县| 涞水县| 湘潭市| 白城市| 贵德县| 汕头市| 长兴县| 天全县| 闻喜县| 夏津县| 桃源县| 改则县| 定南县| 和政县| 湖口县| 应城市| 区。| 林甸县| 临清市| 宜黄县| 娄烦县| 盱眙县| 政和县|