Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM Init and Start

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

like image 612
Al Lemieux Avatar asked Mar 06 '19 02:03

Al Lemieux


People also ask

What is npm init for?

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.

Is npm init required?

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.


Video Answer


2 Answers

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.

like image 194
Evan Winter Avatar answered Oct 22 '22 02:10

Evan Winter


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/

like image 26
Kensam Avatar answered Oct 22 '22 00:10

Kensam