grunt init:node not working - node.js

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

Related

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

Where to install gulp?

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).

'cmd' - not able to get the `grunt` version

I have installed the grunt using this command : npm install -g grunt-cli after i installed i am trying to fetch the grunt version using this command :
grunt --version - But i am not getting any output. what is the issue here? do i require to set the env variable or something?
please help me.
You would need to install Grunt globally as admin. Grunt docs recommend to use sudo when installing. This would be recommended for any Grunt or Gulp plugins you are installing globally. Run the same command npm install -g grunt-cli in admin command line then try grunt --version once more.
I'd recommend posting a separate question for the grunt processing as that involves much more functionality. A good example on a sample gruntfile can be found at Sample Gruntfile and includes processing js and html files for various tasks.
Let me know if that helps.
Thanks!

"grunt install" returns error on Ubuntu

I get the following error when I try to run "grunt install" on a Ubuntu 14.04 box that has the latest nodejs installed from NodeSource.
jit-grunt: Plugin for the "install" task not found. If you have
installed the plugin already, please setting the static mapping. See
https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "install" failed. Use --force to continue.
Aborted due to warnings.
Here is the part of Gruntfile.js related to jit-grunt:
require('jit-grunt')(grunt, {
express: 'grunt-express-server',
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn',
protractor: 'grunt-protractor-runner',
injector: 'grunt-asset-injector',
buildcontrol: 'grunt-build-control'
});
Can someone point to the right direction?
What is the grunt install task? Can you please paste your package.json file here so we may see your dependencies?
The reason jit-grunt is outputting that error is because it cannot find a node module folder named grunt-contrib-install, grunt-install, or install, with a tasks/ folder with JS files that register a Grunt task named install.
Do you mean either of these packages? If so, you have to call them via their registered task names:
- https://www.npmjs.org/package/grunt-npm-install – grunt npm-install
- https://www.npmjs.org/package/grunt-auto-install – grunt auto_install
For the grunt-auto-install package, you will need to add it to jit-grunt's static mappings, like you have with grunt-express-server and others.
If it's not the above, apart from "maybe you mistyped?", the only other answer I can offer is similar to the assumption #waqas-ahmed made: that you mean to install dependencies and devDependencies from your package.json file, and that perhaps you mean to call npm install, not grunt install.
Try as below:
1) npm install -g grunt-cli
This will put the grunt command in your system path, allowing it to be run from any directory.
Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.
2) npm install grunt --save-dev
The easiest way to add Grunt and gruntplugins to an existing package.json is with the command npm install --save-dev. Not only will this install locally, but it will automatically be added to the devDependencies section, using a tilde version range.
for further assistance follow this link
http://gruntjs.com/getting-started

How to install the Grunt task runner?

I am trying to install Grunt (on Windows).
The documentation (http://gruntjs.com/getting-started) says to install grunt-cli and explains that this is not the Grunt task runner but just the program to allow the grunt command to be run from any folder. Ok. Fine. I've done that. My next question is; how to install the Grunt task runner. The implication of the docs is that this will be installed locally in my project directory.
How do I do that?
The project already has a Gruntfile.js and a package.json & works on another machine. I'm just trying to get it run locally.
Specifically I get this message:
"... a Gruntfile wasn't found or Grunt hasn't been installed locally to your project"
Thanks
--Justin Wyllie
npm install --save-dev grunt to install it just like any module and add it to your package.json file as a development dependency.
grunt may also already be listed as a dependency, in which case you may just need to run npm install to install all dependencies.

Resources