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
Description. npm init <initializer> can be used to set up a new or existing npm package. initializer in this case is an npm package named create-<initializer> , which will be installed by npx , and then have its main bin executed -- presumably creating or updating package.
It is not required. You can install packages without, and everything will work. npm init can do basically two things: ask for basic project info to include in packages.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With