NPM install + use local modules? on windows - javascript

I created a package.json and added the needed dependencies (grunt, bower, jasmine etc)
when I run
npm install
it correctly installs all the modules in
$pwd/node_modules/*
however when I try to USE those modules:
bower init; grunt init
i get
sh.exe: (bower / grunt / w.e) Command not found
I can solve this by using
npm install -g (package name)
but my understanding is the "-g" makes the install global? (is that correct?)
I want to be able to use the packages i installed locally...is this possible?

You can use npm run-scripts to create a command which will run the local copies of bower and grunt that you have installed.
In package.json, add a key like this:
"scripts": {
"init": "bower init; grunt init"
}
Then run the command npm run init.

Related

What is difference between local and global Node package installation?

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.

how to npm install only devDependencies with node 8.7.x?

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.

Ready made package.json & gulpfile.js (gulp)

https://github.com/BlackrockDigital/startbootstrap-freelancer
When I download this template, I have ready made package.json & gulpfile.js.
How can I install all devDependencies? Should I use defaul construction for every plugin:
npm i [plugin_name] [another_plugin_name] --save-dev
or another quick command?
Shoud I begin work with
gulp init
?
Running
npm install or npm i
will install both dependencies and dev dependencies

gulp - do i have to install plugins for every project?

I have a question about gulp.
I understand that when i want to use gulp with my project I need to run "npm init" for package json, I need to install gulp locally (assuming globally is already installed) with "npm install --save-dev gulp" and i need to install all the plugins i want to use (--save-dev so locally?). Im using about 10 gulp plugins and thats about 300mb+ of download (i dont understand why) for every project. Also the download is taking way too much time.
My question is: do i have to install all plugins for every new project i want to run with gulp? Or can i just copy gulp file and run it without installing plugins all over again because it takes 30 minutes to install them...
No. You basically have these options:
npm install pkg // install package locally
npm install -g pkg // install globally
npm install pkg --save // install package locally and save to package.json
npm install -g pkg --save // install package globally and save to package.json

Bower will not install packages when .bowerrc exists

I'm trying to install packages using Bower.
Without a .bowerrc file, it works. For example, bower install angular#1.0.6 will install nicely inside ./bower_components.
If there is a .bowerrc with { 'directory' : 'public/javascripts/vendor' }, bower install angular#1.0.6 will not work. Actually, the output of that command is nothing. It simply prints a blank line, then the next line is my terminal prompt. The package is not installed anywhere.
However, if there is an empty .bowerrc file, it will install the package inside ./bower_components.
Why is it not installing the packages and how can I fix it? (so they will install)
Additional info:
No bower command works. bower will fail similarly. bower help too. In fact, bower anything will too.
I just solved this. I uninstalled and reinstalled bower, and now it works. :S
sudo npm rm -g bower
sudo npm install bower -g
Now everything works fine!
The solution here is simple :
Install Bower in your public directory ( Not your app/node master directory )
For example, mynodeapp/public - npm install bower
Then, set up bower from this directory : bower init
Create your .bowercc file, and add to it :
{
"directory" : "vendor"
}
//Where vendor is your custom fldr
Thats it. Now whenever you run a bower install command from within the public directory, it will either create or save to that "vendor" directory.
Everyone seems to have trouble because they are installing Bower outside their public folder.
Try to run with -f flag (force)
bower -f install
I think that you should be reinstall the bower
npm rm -g bower
npm install bower -g

Categories

Resources