Where to install gulp? - node.js

I'm trying to leverage from Elixer so I started to get up and running. I've installed Node and Npm. Later I also installed Gulp using sudo npm install gulp -g. But this installed Gulp in my project directory, resulting in a massive file transfer from my local host to the webserver. Is it necessary to install Gulp inside the project directory? Or is there a better way to install it somewhere else and use it for any project needed?
Sorry if this is a total beginners question but I can't seem to find an answer online. Thanks.

There is only few steps to start use it.
Install globally $ npm install --global gulp
Install directly to your project root dir $ npm install --save-dev gulp
Create gulpfile.js in root dir
Then in your new gulpfile do the follow:
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
and after that just type gulp command in terminal to execute default task
here is documentation to help you started with gulp docs and here you can find packages to use it npmjs.com
Tip: if you on OSX use sudo to install npm/jspm/gulp etc

sudo npm install gulp -g shouldn't be installing gulp in your project directory. However, Gulp does always need to be installed locally in the project folder in order for it to work. Otherwise, you will get an error when trying to run Gulp. The -g global installion of Gulp is only needed for linking the shell to the binary $ gulp; it will dispatch to the local gulp program as soon as it is called.

Gulp, bower, ... are dependencies.
The command npm install ... will download the module to the directory named node_modules. They need to be (litterally) a part of your project. Think of it as a pure JS library (as it actually is).

Related

Gulp: /usr/local/bin/gulp: No such file or directory

Whenever I run gulp, I get the following error:
/usr/local/bin/gulp: No such file or directory
I've followed the answers to several related questions on SO, but none have solved my issue. I've been using gulp without issue for months, but managed to screw it up somehow.
I've removed gulp and gulp-cli (using npm) both locally and globally.
After running the following:
npm install -g gulp-cli
npm install --save-dev gulp
Any command using gulp, even gulp -v returns the error mentioned above. There are no errors during the installation.
I've confirmed there is nothing at /usr/local/bin/gulp, but shouldn't reinstalling things recreate whatever files are supposed to be there?
Any help is appreciated.
EDIT:
Installing gulp globally npm install -g gulp doesn't fix anything.
Do you want to install gulp locally or globally?
Locally
npm install --save-dev gulp gulp-cli should do the trick. You can then run it using:
./node_modules/.bin/gulp
npm run gulp if you add gulp to the scripts section of package.json.
Globally
Most likely you have a $PATH issue.
Did you check where your global libraries are installed by NPM?
npm list -g
Does installing any other global library work, or is it specific to Gulp?
-- Edit --
If you are using NVM, you should add the NVM setup to your rcfile (that is, ~/.bashrc, ~/.zshrc, ~/.profile or similar). You can do so by appending these lines to your rcfile.
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
This will load NVM and update your PATH so that your shell is able to find gulp (or any other globally-installed program by npm or yarn).
Try npx gulp so that npm using the gulp version that is installed in your dependencies.

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.

Setting Up Node & NPM

I have installed MEAN IO a few times. Everytime I get it installed I can usually get one project going and then things just stop working. For example I have one project going. But then when I go to create a new project now it says commands are not found
gulp
mean init myApp
bower
So I installed with the installer at https://nodejs.org/en/
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
I have node_modules at
usr/local/lib/node_modules
But I also have packages at
/usr/local/bin/
Either way I cant get these commands to run... Any ideas how I can get things setup and solid?
Try installing mean-cli, bower and gulp globally, like so:
npm install -g mean-cli bower gulp

grunt init:node not working

I'm trying to do an intro grunt tutorial. I've installed git, node.js, and grunt globally (or at least I thought I did using: npm install -g grunt (which installs). I then made a quick directory and entered it (mkdir demo, cd demo), but when I type:
> grunt init:node
at the prompt I get the following:
grunt-cli: The grunt command line interface (v0.1.11)
Fatal error: unable to find local grunt
If you're seeing this message, either a Gruntfile wasn't found or hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
Which I've looked at and it says to do what I'm doing and what the tutorial mentions??? Any ideas what I've done wrong? Node.js and Git have been working fine so I can only assume it is grunt or the install that has failed.
Thanks
with grunt you need two elements. a global grunt-cli as you have installed using npm install -g grunt-cli and also a local (to the project) copy of grunt itself. so in the folder of your project install this with npm install grunt --saveDev this will install a local grunt and also add it to your devDependencies in your package.json file. you will also need a Gruntfile.js in the project folder. This is a great write-up http://www.integralist.co.uk/Grunt-Boilerplate.html

How to use grunt-html installed globally?

I would like to use grunt-html task to check my HTML files.
I install the task locally with npm install grunt-html and use it in grunt.js as follows:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-html');
grunt.initConfig({
htmllint:{
all:['*.html']
},
});
};
Now I would like to install the grunt-html task globally.
Unfortunately after removing the local grunt-html node module and installing it globally grunt fails to load the task. While running grunt htmllint I get:
>> Local Npm module "grunt-html" not found. Is it installed?
If I remove grunt.loadNpmTasks('grunt-html'); from the grunt.js file I get:
Task "htmllint" not found. Use --force to continue.
So my question is how to use grunt-html installed globally?
gruntjs doesn't currently support loading globally-installed grunt modules from loadNpmTasks, per the documentation of grunt.loadNpmTasks:
This plugin must be installed locally via npm, and must be relative to the grunt.js gruntfile.
Of course, if you really insist on installing it globally, a hack would be to create a symlink (ln -s) from your local node_modules directory to your global node_modules/grunt-html directory.
If you're doing module development, another alternative would be to use the under-appreciated npm link command that lets you locally install a module that exists elsewhere on you system (see npm help link for usage information).
Both of these approaches, though, don't allow you to truly install the grunt-html package globally.

Resources