npm/grunt: is it possible to install grunt without npm? - node.js

I am having so much problems with the proxy system of my entertprise
I was changing parameter using npm config set changing the variable proxy and http-proxy.
I installed in my .npmrc next lines
npm config set proxy http://my_user:my_password#10.3.12.130:8080 -g
npm config set https-proxy http://my_user:my_password#10.3.12.130:8080 -g
What I have in my mind it is try to install grunt in VS2012 without using npm, maybe like nuget.
Is it possible?
I am getting this error page when I am using npm install -g grunt-cli:

Yes it is possible, you can download grunt and run it in your node.js environment, if your only problem is proxy or firewall but you have working node.js environment then just download it from the github.
You can download any npm package which is published also on the github and then copy it manually to you node_modules folder. Just beware that those packages may have dependencies on their own. SO that means you should run npm install in those downloaded folders and if it doesn't work do it manually for every dependency recursively until you are finished.

No, it is not possible.
This is from the Grunt getting started guide:
Grunt and Grunt plugins are installed and managed via npm, the Node.js
package manager. Grunt 0.4.x requires stable Node.js versions >=
0.8.0. Odd version numbers of Node.js are considered unstable development versions.

Related

How I can Download npm packages to use them into offline enviroment?

My development machine has no internet connection and I want to install gulp on my project:
npm install -g gulp
On my machine with internet connection I don't have right to install any piece of software (node or npm).
There is a way to download gulp package (like I do for nuget packages) and to install it to my project?
When installing npm modules globally, they are by default saved to
C:\Users\{User}\AppData\Roaming\npm
You need to download the modules and manually place them in that folder, and make sure that the path has been added to Path environment variable on your computer.
Since you are not able to download them through npm, simply go to the gulp github repository, and place the content of that repository in a folder named gulp, in the path above.
npm install -g gulp
in your project directory use
npm link gulp
this will create shortcut of gulp module in node_modules so that you don't have to download it, make sure to upvote.

Doesn't npm install check for a global version first?

I just setup a test, and tried to npm install express even though express already exists globally on my system. To my surprise, instead of using the global version, it ended up re-installing a version locally!? Isn't it supposed to use the global version... Or am I suppose to use -g every time, even when I only want to use the existing global version. Otherwise, what's the point of installing anything locally!?
The answer is "NO". It isn't supposed to use your global version.
If you want to use your global version, then you doesn't need to execute npm install at all because it is already installed.
If you do it then, obviously, you are saying "I want to install it locally to my project". And more than that: "I want to install its latest version unless it is declared in my package.json with other explicitly specified version".
In fact, the actual question is: Why in the hell would you want to not install a dependency of your project locally? To have more version mismatch issues?
As #anshuman_singh says, best practice is to always do an npm install --save.
You are able to use globally installed packages, of course. It could be handy for fast testing code that you will drop just after a few hours or so.
But, anyway: If you doesn't have really hard disk or network bandwidth issues, installing all dependencies locally will avoid you too much trouble in the future.
On the other hand, uploading that modules to your code repository is also a bad idea (maybe that is what you were trying to avoid) because, with different versions of node, most native modules won't work if not rebuild. But most VCS support ignoring files and or directories that must not be uploaded.
For example, in git (.gitignore file):
**/node_modules
In summary:
npm init (if you didn't already it).
npm install --save for all your project dependencies.
npm install --save-dev for dependencies not needed in production (testing stuff).
Don't upload node_modules to your VCS.
After new checkout: npm install or npm install --production (to not install dev-dependencies).
npm install -g only for tools you will use in console.
This way, you are sure that you will have in production (or other dev environments) the exact same version of each package.
And, finally, if you ever want to upgrade some package to its latest version, simply run:
npm install --save <pagkage_name>#latest.
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
The first option is the best in my opinion. Simple, clear, explicit. The second is really handy if you are going to re-use the same library in a bunch of different projects
Install locally-
npm install moduleName
install locally and save in package.json-
npm install moduleName --save
install globally-
npm install moduleName -g

Building on Heroku -avoiding global dependencies

According to Heroku I should avoid global dependencies when asking Heroku to build my project. But I still want Bower and Grunt on the command line.
My question is: how then should I be running these tools?
Rather than installing them with npm install -g, should I be adding paths from node_modules to PATH, or the like? (Ubuntu)
If Grunt/Bower are installed globally on development machines -say when someone new starts on the project -then presumably npm install -g grunt-cli might give a different Grunt version to what's in package.json. Hence what Heroku runs and what developers run might accidentally differ.
(Or is that unlikely to be a problem?)
The best practice is to keep everything local, with npm install --save.
That way you can align versions for everyone in the team simply by tweaking the package.json file.
If you only need Bower and Grunt etc. to be available in your dev environments, then install them with npm install --save-dev. This will cause them to be saved in a devDependencies section in your package.json. Dependencies referenced therein will not get distributed to production (e.g. Heroku), but will be available in all your dev environments.
If you really do need Bower and Grunt etc. to be available on Heroku, then install them with npm install --save.
At any rate, npm should automatically save symbolic links to your executables (e.g. grunt-cli) in directory node_modules/.bin, and should take care of adding node_modules/.bin to your PATH, so you don't have to worry about that.

NPM Experts! Does NPM need to be installed with every JointsWP Gulp Sass project

I'm using JointsWP (an excellent Foundation 6 port to Wordpress).
I'm using the Sass version and it's working great. However, I seem to have to install npm with every project. Is this nessesary?
Is there a way to install npm globally and link to it from my project? Or have the project find it automatically?
I think you are confused about what the command npm install actually does. npm install installs all the npm dependencies for your project into the node_modules directory. It doesn't actually install npm. To run npm install you have to have Node.js installed (npm is included with node).
So to answer your question, yes it is necessary to run npm install for every project.
Relevant Article: Global vs Local installation
The article above shared by Colin Marshall is great and sums up the answer perfectly.
In general, the rule of thumb is:
If you’re installing something that you want to use in your program,
using require('whatever'), then install it locally, at the root of
your project. If you’re installing something that you want to use in
your shell, on the command line or something, install it globally, so
that its binaries end up in your PATH environment variable.
So to answer your question, is it possible? Yes.
Is it recommended? No.
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
You can install gulp sass globally with the command:
npm install -g gulp-sass

Can't you install socket.io as a global package?

I tried to install socket.io with the -g switch
npm install -g socket.io
and it installed correctly I think.
but running the app it throws the cannot find module error.
Local install, i.e. if socket.io is present in node_modules in my project/package, works though.
So can't it be installed globally?
You misunderstood the meaning of global installation. It allows you to access packages directly from your console. But if you want to require package into your own application, you should add it as a dependency into your packaje.json and install it locally.
Here is the quotation from npm documentation:
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
When you install a package globally, what you're saying is that you want to use it in your shell (cmd.exe). Something like nodemon is such a package that you would install globally but not include locally as it doesn't need to be included for your app to run, but instead is used to benefit you as the developer.
You install packages without the -g switch when it is necessary for your app to run. In this case it is necessary for socket.io to be installed. Note that locally installed packages should go into your packages.json file so that anyone who installs your app at a later date automatically gets the included packages. Global packages do not appear here.

Resources