I'd like to know if Javascript's npm installs dependencies OS-wide like Python's pip (if pip is not using a virtualenv), or if npm installs dependencies more like Java's mvn which stores the things in a local pom.xml file (to me mvn feels more like if it was always in a virtualenv if compared to pip).
So I mainly want to know if it's OS-wide installs or local installs that are performed with npm.
Both!!
npm install -g PACKAGE_NAME will install the package globally.
npm install PACKAGE_NAME will install the package locally in the current folder, under node_modules/.
npm install --save PACKAGE_NAME will install the package locally and save it as a dependency in your package.json.
Checkout https://www.sitepoint.com/beginners-guide-node-package-manager/
if you execute just npm install <dependency name> you are telling node to install package only on your current directory this will also create node_modules in current directory you are installing.
and if you execute the npm install -g <dependency name> with the -g you are saying that you want the node to install the dependency globally and the package will be save on the global node_modules. and most of the global dependencies can be access using CLI
example.
$ npm install mocha
you can execute the command in the current directory execute the npm install or where the node_module is
$ $PWD/node_modules/.bin/mocha -v
if you
$ npm install -g mocha
you can execute the command anywhere in your directory on the terminal
$ mocha -v
Related
I ask this question because I have been installing nodemon with npm and I see the results of installing through the suggested command at first sight, at the right side of the screen:
npm i nodemon
It is different from the installation instructions you can read above, on the Installation section. There we see:
global installation:
npm install -g nodemon
install nodemon as a local project dependency:
npm install --save-dev nodemon
The thing is, what is difference between
npm i nodemon
and
npm install -g nodemon
When I use the first command it tells me typical "nodemon is not recognized as internal or external command, operable program or batch file". To solve it I must install globally.
When you run npm i nodemon nodemon is installed as a local project dependency, to run nodemon on the CLI you would have to provide the pull path to it's installation, typically you would want to make this reference in your project's package.json file's scripts property, for instance:
{
...
"scripts": { "nodemon": "nodemon index.js" },
...
}
This can then be executed by running npm run nodemon.
On the other hand running npm install -g nodemon or npm i -g nodemon installs nodemon on the global scope where it is referenced in your system PATH variable, that way you can easily call nodemon on the CLI and since it's full installation path is referenced in your system PATH variable it would execute like every other CLI command.
Browser is made available to the current project (where it keeps all of the node modules in node modules) after local installation. It will not be available as a command that the shell can resolve until you install it globally with npm install -g module, in which case npm will install it in a location where your path variable will resolve this command. Typically, this is only good for using a module like so var module = require('module');
This documentation will help.
I just installed module underscore js using npm install underscore. I want to know how and where NPM would store that module so I can import that module in my .js file.
Using npm install without the -g flag will install the modules in the current directory under node_modules
Using npm install -g, it would install at following address on computer(MAC)
/usr/local/lib/node_modules/
The usual way of installing only devDependencies was to use npm install --only=dev (or --only=production if you want only dependencies).
This doesn't work anymore in 8.7. If I run this command, npm will try installing all dependencies. Or at least, it runs a /usr/bin/git ls-remote -h -t on packages that are not in devDependencies. Those packages being in private git repos, the npm install fails for me.
This didn't happen until I upgraded to 8.7.0, from 7.4.0
The npm cli documentation still shows the old way of doing it though.
Is there a new syntax for that option?
From the output of npm help install:
npm install (in package directory, no arguments):
Install the dependencies in the local node_modules folder.
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
By default, npm install will install all modules listed as dependencies in npm help 5 package.json.
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
So it seems you can install only dependencies with --production; not sure if there's a way to only install devDependencies.
my github repository application how to Create mypkgname CLI package manager application
I have registered this package in npm, so I can install it globally:
npm install -g mypkgname-cli
mypkgname init myApp
cd myApp
npm install
npm start
just examples
npm install -g mern-cli
npm install -g #angular/cli
You may want to use some cli arg pareser like commander
or yargs
There are many other command line argument parsers.
This tutorial here explains the usage well https://developer.atlassian.com/blog/2015/11/scripting-with-node/
Important parts include
adding #!/usr/bin/env node on top of your entry point script.
in package.json, something like
"bin": {
"mycliapp": "index.js"
}
then running npm link or npm install -g on your app.
I used Homebrew to install Node.js, then used npm install to install Grunt and its dependencies, but after the installation completed, I was not able to run Grunt:
zsh: correct 'grunt' to 'grn' ÆnyaeÅ? n
zsh: command not found: grunt
What is the proper method of installing Grunt so I do not get this error?
To use Grunt on the command line, you have to install the command-line interface:
npm install -g grunt-cli
The -g flag is for installing the module globally, which will also create a PATH variable for Grunt.
npm install -g grunt-cli => This will put the grunt command in your system path