I am new to nodejs and gulp stuff. I working on a nodejs project in which I have to run jslint on all the files. I am using gulp for this purpose.
My problem is that In order to run gulp on cli I don't want to install gulp globally and also does not want to update my path variable, So I have installed gulp and other node modules in my project locally using the package.json file
cd myproject
npm install
Since I don't want to install gulp globally and want to run the local gulp I have added script in my package.json file like this as given in this question
{
"name": "",
"version": "1.0.0",
"main": "index.js",
"private": true,
"dependencies": {
"async": "1.5.0"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-jslint": "^0.2.2"
},
"scripts": {
"gulp": "./node_modules/.bin/gulp" // is this correct?
}
}
Add added a gulpfile.js inside my myproject folder
var gulp = require('gulp');
// include plug-ins
var jslint = require('gulp-jslint');
// JS hint task
gulp.task('lint', function() {
gulp.src('./common/srp/*.js')
.pipe(jslint())
.pipe(jslint.reporter('default'));
});
gulp.task("default", ["lint"]);
But now on my command line inside myproject folder, when I run gulp and gulp lint I get an error
user1-VirtualBox:~/myproject$ gulp lint
/usr/local/node-v0.10.26-linux-x64/bin/gulp No such file or directory
Its looking for gulp in the global node module.
Is there a way to make gulp run on cli without installing globally and updating PATH variable.
Any help will be appreciated Thanks
With your code you should be able to run command npm run gulp
Please try
One way to define script is
If in case you are not able to run gulp command in your project, run
It will link your global install gulp with your local project. Then try
If it is showing you the version then you are done. Now you can run any gulp command as you want.
Just another alternative that will work locally but will give you global like feeling. Add to your shell config i.e.
~/.bash_profile
the followingexport PATH=$PATH:./node_modules/.bin
you have tosource
that file, executerehash
or just open a new shell and thengulp
(and any other script inside that folder) shall be available as a global command.You can find any executable installed by npm in
node_modules/.bin
. So you can run gulp locally using:You can find more information at no command 'gulp' found - after installation
Globally install gulp in C:\Users\%USERNAME% using this command
You can install any other gulp methods you need to use.. Ex:
Then at the directory you wish to use GULP. Open the command prompt (Shift + RightClick) then install locally and you'll be able to execute gulp.
You can install any other gulp methods you need to use.. Ex:
Check in your project
node_modules/.bin
folder and make sure gulp is in there. I had a case where it wasn't there that I never tracked down the reason for. If it isn't there, try re-installing gulp locally and see if it shows up. If that doesn't work and you get tired of the problem, thegulp-cli
package will fix it for sure, but that shouldn't be something you have to do.The simplest solution I know of is to use
npm bin
:This keeps you away from hard-coding any paths.