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.