Can no longer run any node packages after reinstall - node.js

My node suddenly stopped working so I removed everything and installed node with homebrew.
Now I cant install grunt, nodemon, bower etc.
Pers-MacBook-Air:backendMD perstrom$ sudo npm install -g grunt-cli
Password:
/Users/perstrom/.node/bin/grunt -> /Users/perstrom/.node/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /Users/perstrom/.node/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.5)
└── findup-sync#0.1.3 (lodash#2.4.1, glob#3.2.11)
Pers-MacBook-Air:backendMD perstrom$ grunt --version
bash: grunt: command not found
Pers-MacBook-Air:backendMD perstrom$
What can be wrong? How do I debug this?

Try to expend your path (make sure this folder contains the bins):
export PATH=/Users/perstrom/.node/bin:$PATH

Related

express: command not found , has worked before?

I'm working on a OSX 10.10.4, I have worked with node.js and express before on this computer.
But now when I want to start a new application, the computer won't recognize the command express anymore.
I've tried installing it with all these commands:
- npm install express
- npm install -g express
- npm install express -g
- sudo npm install -g express
- sudo npm install express -g
- npm install express-generator
- npm install -g express-generator
- npm install express-generator -g
- sudo npm install -g express-generator
- sudo install express-generator -g
- sudo npm install -g express-generator#3
- sudo npm install -g express-generator#4
But it still doesn't recognize the command express
This is the output when I install without the -g
npm install express
express#4.13.3 node_modules/express
├── escape-html#1.0.2
├── merge-descriptors#1.0.0
├── cookie#0.1.3
├── array-flatten#1.1.1
├── utils-merge#1.0.0
├── cookie-signature#1.0.6
├── methods#1.1.1
├── fresh#0.3.0
├── range-parser#1.0.2
├── vary#1.0.1
├── path-to-regexp#0.1.7
├── content-type#1.0.1
├── etag#1.7.0
├── parseurl#1.3.0
├── content-disposition#0.5.0
├── serve-static#1.10.0
├── depd#1.0.1
├── qs#4.0.0
├── finalhandler#0.4.0 (unpipe#1.0.0)
├── on-finished#2.3.0 (ee-first#1.1.1)
├── debug#2.2.0 (ms#0.7.1)
├── proxy-addr#1.0.8 (forwarded#0.1.0, ipaddr.js#1.0.1)
├── type-is#1.6.6 (media-typer#0.3.0, mime-types#2.1.4)
├── accepts#1.2.12 (negotiator#0.5.3, mime-types#2.1.4)
└── send#0.13.0 (destroy#1.0.3, statuses#1.2.1, ms#0.7.1, mime#1.3.4, http-errors#1.3.1)
and when I install with the -g
sudo npm install -g express-generator
Password:
/Users/Maiteh/.node/bin/express -> /Users/Maiteh/.node/lib/node_modules/express-generator/bin/express
express-generator#4.13.1 /Users/Maiteh/.node/lib/node_modules/express-generator
├── sorted-object#1.0.0
├── commander#2.7.1 (graceful-readlink#1.0.1)
└── mkdirp#0.5.1 (minimist#0.0.8)
I have tried some other stuff like the PATH and nodejs-legacy, but none of them work.
With the sudo apt-get install nodejs-legacy the computer doesn't find the command apt-get.
The reason I got express:command not found after I installed was because my $PATH didn't know where express was.
To anyone wanting to install the express command line tools I did this
sudo npm install express-generator -g
which resulted in
/usr/local/share/npm/bin/express -> /usr/local/share/npm/lib/node_modules/express-generator/bin/express
express-generator#4.13.1 /usr/local/share/npm/lib/node_modules/express-generator
├── sorted-object#1.0.0
├── commander#2.7.1 (graceful-readlink#1.0.1)
└── mkdirp#0.5.1 (minimist#0.0.8)
when I tried express --version I got a command not found
Open your bash_profile from terminal with open ~/.bash_profile
After that add the path you got after you installed express, in my case it was
/usr/local/share/npm/lib/node_modules/express-generator/bin/express
Add this to your bash_profile
export PATH=/usr/local/share/npm/lib/node_modules/express-generator/bin:$PATH
Save the file and go back to terminal. Enter hash -r and then quit terminal and start it again.
Now if you try express --version for example you should see that the command line tools are working.
There's kind of a mishmash of problems you're describing here, so I'll try to address them one at a time.
Express is a popular framework for node.js. The typical way to add it to your project is to do npm install --save express and then it will save it into your package.json file and install it into node_modules. Adding -g to that command would attempt to install it globally, but that's not how express is used. Express is used on a per-project basis. See their website for details.
In the big list of commands you've run, you mention express-generator. Express-generator is a tool that lets you quickly build out some boilerplate to make starting an express project a bit easier. Since express-generator is meant to be run globally and not inside a project, you DO install it with the -g flag. See their website for details on use and installation.
You're trying to install some more node stuff with the apt-get command. That command is used for package management on Linux (typically Ubuntu/Debian) machines. Mac OS X doesn't come with it (and you absolutely don't need it). Any instructions that mention running apt-get are not targeted towards Mac users.
Essentially, I don't think you have a problem, the logs you show are exactly what I'd expect to see. Generate a boilerplate project with express-generator and you should be all set to start working on your express project. Good luck!

Strange npm behavior when installing packages like grunt

I run the following command in my bash and I get the related results:
merianos#merianos-desktop:~$ sudo npm install -g grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.7)
└── findup-sync#0.1.3 (lodash#2.4.2, glob#3.2.11)
and
merianos#merianos-desktop:~$ grunt
/usr/bin/env: node: No such file or directory
I also have try to install bower and gulp but again, when I try to execute them, I get a message related to the grunt above.
Can someone please help me ?
Just to know, I just installed Ubuntu 15.04. I don't know if that helps :)
Ubuntu package nodejs provide a binary as a /usr/bin/nodejs, not a /usr/bin/node, so most of cli tools can't find it. To solve the problem you need to make a symlink:
sudo ln -sT /usr/bin/nodejs /usr/bin/node

'Command not found" after *attempting to* install grunt

To start out, I've already tried solving using the following resources:
Node package ( Grunt ) installed but not available
http://gruntjs.com/getting-started
http://coolestguidesontheplanet.com/install-gruntjs-osx-10-9-mavericks/
None of the above worked.
I'm trying to install grunt on my Mac (running 10.10.3), and after the npm install command completes, the grunt --version command returns 'command not found'.
Here's the output of my terminal window:
$ sudo npm install -g grunt-cli
/Me/local/bin/grunt -> /Me/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /Me/local/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.5)
└── findup-sync#0.1.3 (lodash#2.4.1, glob#3.2.11)
$ grunt --version
-bash: grunt: command not found
My PATH variable:
/usr/local/bin:/usr/local/share/npm/lib/node_modules/grunt-cli/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:b0VIM 7.3:/usr/local/git/bin:usr/local/bin/

Cannot install express-generator globally with nvm

I'm using NVM to avoid using sudo to install things globally. It works fine for everything from Bower, to Grunt, etc. However, when I do npm install -g express-generator it doesnt work. For example, heres what I get when I globally install Bower:
npm install -g bower
/Users/jrdillon522/.node/bin/bower -> /Users/jrdillon522/.node/lib/node_modules/bower/bin/bower
bower#1.3.12 /Users/jrdillon522/.node/lib/node_modules/bower
├── is-root#1.0.0
...
...
...
├── update-notifier#0.2.0 (semver-diff#0.1.0, string-length#0.1.2, latest-version#0.2.0, configstore#0.3.1)
├── mout#0.9.1
├── handlebars#2.0.0 (optimist#0.3.7, uglify-js#2.3.6)
├── inquirer#0.7.1 (figures#1.3.3, mute-stream#0.0.4, through#2.3.6, readline2#0.1.0, lodash#2.4.1, cli-color#0.3.2, rx#2.3.14)
└── insight#0.4.3 (object-assign#1.0.0, async#0.9.0, chalk#0.5.1, os-name#1.0.1, lodash.debounce#2.4.1, tough-cookie#0.12.1, configstore#0.3.1, inquirer#0.6.0)
Works fine right? When I install the Express Generator I get the classic error:
npm ERR! Please try running this command again as root/Administrator.
So I run sudo npm install -g express-generator. Heres what I get then:
sudo npm install -g express-generator
Password:
/Users/myName/.node/bin/express -> /Users/myName/.node/lib/node_modules/express-generator/bin/express
express-generator#4.9.0 /Users/myName/.node/lib/node_modules/express-generator
├── mkdirp#0.5.0 (minimist#0.0.8)
└── commander#1.3.2 (keypress#0.1.0)
➜ ~ express -v
zsh: command not found: express
➜ ~
Why??
It looks like your bin path (/Users/myName/.node/lib/node_modules/express-generator/bin/express) isn't added to your environment.
If you modify your .bashrc file, add the following line to the bottom of your file to make things work as expected:
export PATH=$PATH:/Users/myName/.node/lib/node_modules/express-generator/bin
Then retry the installation.

No local gulp install found even after installing npm install -g gulp

I tried to install gulp by
npm install -g gulp
The output seems to be something like this. (i have skipped some logs)
npm http 304 https://registry.npmjs.org/string_decoder
npm http 304 https://registry.npmjs.org/lodash._htmlescapes
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
gulp#3.6.2 /usr/lib/node_modules/gulp
├── tildify#0.2.0
├── pretty-hrtime#0.2.1
├── deprecated#0.0.1
├── archy#0.0.2
├── semver#2.2.1
├── chalk#0.4.0 (has-color#0.1.7, ansi-styles#1.0.0, strip-ansi#0.1.1)
├── orchestrator#0.3.3 (sequencify#0.0.7)
├── liftoff#0.9.8 (extend#1.2.1, minimist#0.0.8, resolve#0.6.3, findup-sync#0.1.3)
├── vinyl-fs#0.1.4 (graceful-fs#2.0.3, map-stream#0.1.0, mkdirp#0.3.5, vinyl#0.2.3, glob-stream#3.1.9, glob-watcher#0.0.6)
└── gulp-util#2.2.14 (lodash._reinterpolate#2.4.1, dateformat#1.0.7-1.2.3, minimist#0.0.8, vinyl#0.2.3, multipipe#0.0.2, through2#0.4.1, lodash.template#2.4.1)
In the above script i can see a line
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
which i guess is making a simulink in bin folder. So i should be getting gulp globally but i get the this error.
No local gulp install found in /var/www/ksapp
Any idea why i am getting this error.
Thanks
As pointed out in the doc, you should install it globally (you did that) and add it to your project dev deps (locally):
npm install gulp --save-dev
I faced the same issue. Got it resolved by creating a link
npm link gulp
Check /home/username/.npm directory: maybe groups/owner of files is root. Change to username:
chown -R username.username /home/username/.npm
I've recently run into the "Local gulp not found" error message. I was able to work past it by creating a symlink from the global node_modules directory to the local project directory where my gulpfile.js is located.

Resources