18

I'm using npm for a local project and I want to know if I have to use npm init every time I start a session? I think the answer is yes.

If I restart my machine for example, do I have to do npm init? Do I have to do npm install and npm start each time?

Thanks

Al Lemieux
  • 307
  • 1
  • 3
  • 7

3 Answers3

19

No, you only have to do npm init when you're first creating a project. It essentially just creates the package.json file (https://docs.npmjs.com/cli/init.html).

And you should only have to run npm install when you first set up a project for local development, or when changes are made to the project's dependencies. So, usually just once, unless you've made changes. (https://docs.npmjs.com/cli/install.html)

npm start is a script that should be defined in your package.json, and you will likely need to run that every time you begin local development on your project.

Evan Winter
  • 373
  • 2
  • 7
4

When you are creating a node project, you need to have package.json. npm init is a convenient way of scaffolding your package.json; you may need to run it everytime you are starting a new project.

npm install, however, installs your dependencies in node_modules folder. You may need to run this everytime you manually add a dependency to your package.json file.

If you need extra information, check here: https://nodesource.com/blog/an-absolute-beginners-guide-to-using-npm/

-1

npm init is to make new modules you dont ever need to run npm init to start a session at all as far as I can tell