简体   繁体   中英

Do I need to run the command npm install every time I want to compile my project?

I am currently working on a project at a large company, and according to the project I am working on, every time I want to quickstart the app, I would need to first run the command npm install and then run all the additional compiling instructions, but the problem is that running npm install can take a long time, and that is why I am wondering if it is necessary to run this command every time I make a change to the code, and then want to compile and run it.

What exactly does npm install do? If you could explain to me in terms of how we compile and run java code ie javac bob.java && java bob and try to make analogies on that basis, that would greatly help me understand the concept. The way I am currently thinking about it right now is that npm install kind of runs like how javac runs, but I am not sure if that is correct. Thanks in advance!

NPM Install

npm install simply reads your package.json file, fetches the packages listed there from (usually) https://www.npmjs.com/ , and sometimes engages in the build steps for those packages.

So you only have to run npm install when you change your package.json file, and need to fetch new dependencies.

Keep in mind that npm install --save <packagename> (or npm install -S <packagename> ) will update your package.json and run npm install all in one line!

You can view the results of your npm install inside ./node_modules/ .

To compare to java

This might be a helpful resource if you're trying to get stuff done:Getting Started with Node.js for the Java Developer

Javascript is not a compiled language, unlike java. When you invoke javac , the java c ompiler reads in all your .java files, compiles them to java bytecode, and then writes them to .class files, which can then be bundled together into a .jar for execution.

Javascript doesn't do any of this! When you invoke node foo.js , the node executable wakes up, reads foo.js , and gets to work invoking it line by line**. Node does other cool things, including maintaining an event loop (which allows it to operate "asynchronously", and allows it to be very efficient as a webserver-- it doesn't sit around waiting for requests to complete, it carries forward with the next event in the queue.

Node also performs JIT and optimization, these details allow it to improve the performance of sections code it notices are running "hot".

Note also that node.js uses the V8 javascript engine (also used in Google Chrome). Really everything I've said above is handled by V8.

(** Technically there is a syntax checker which is run first, before execution. But this is not a compile step!)

It is not necessary to do "npm install" each time you want to compile. You just need to do it when you change the dependencies of your project.

NPM basically is the package manager for node. It helps with installing various packages and resolving their various dependencies. It greatly helps with your Node development. NPM helps you install the various modules you need for your web development and not just given you a whole bunch of features you might never need. When you start an app, it comes with a package.json file. That package contains the list of node_modules you are gonna need. Whenever you enter npm install, what you are doing is to download that list of node_modules. So yeah, you have to download the modules all over again. #NOTE: In your project, you have a file called package.json. this file is responsible for holding track of your project's dependencies. That's why you have to install it every time #.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM