Command not found when trying to run a nodeschool lesson - node.js

I'm not sure if this is purposeful but when running the...
npm install learnyounode -g
..command in terminal, the module is being created in my home directory. When I try to run the 'learnyounode' command from the directory that I run the npm install from I get the message 'command not found'. I've looked in the usr directory but the learnyounode directory is not in there.
After everything intalls I get the following output
/Users/username/npm/bin/learnyounode -> /Users/username/npm/lib/node_modules/learnyounode/learnyounode.js
learnyounode#0.4.1 /Users/username/npm/lib/node_modules/learnyounode
├── duplexer#0.1.1
├── through#2.3.4
├── boganipsum#0.1.0
├── hyperquest#0.1.8 (through#2.2.7)
├── concat-stream#1.2.1 (bops#0.0.6)
├── bl#0.6.0 (readable-stream#1.0.26)
├── through2-map#1.2.1 (through2#0.2.3, terminus#1.0.9)
└── workshopper#0.7.2 (map-async#0.1.1, tuple-stream#0.0.2, split#0.2.10, mkdirp#0.3.5, xtend#2.1.2, colors-tmpl#0.1.0, terminal-menu#0.2.0, optimist#0.6.1, msee#0.1.1)
ps. I have a fresh install of node in my usr folder. I am more concerned that this problem is going to happen when I want to install other packages via NPM in the future.

I installed without the -g flag and it installed globally.

Trying to install learnyounode,
This path returns:
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

Related

Globally installed npm package not accessible in terminal

I installed protractor through npm install -g protractor which run successfully.
Running npm -g ls --depth=0 shows protractor installed correctly.
azim#azim-desktop:~$ npm -g ls --depth=0
/home/azim/npm-global/lib
├── express-generator#4.13.1
├── generator-angular#0.12.1
├── generator-chrome-extension#0.3.1
├── generator-gulp-angular#1.0.2
├── generator-gulp-angular-subtask#0.9.1
├── generator-karma#1.0.0
├── generator-mocha#0.1.8
├── generator-react-webpack#3.2.2
├── git-remote-mango#0.0.2
├── jshint#2.7.0
├── jsx#0.9.89
├── mango-admin#0.1.1
├── n#2.1.0
├── npm#3.7.2
├── protractor#4.0.0
└── yo#1.6.0
but protractor isn't accessible in terminal.
azim#azim-desktop:~$ protractor
protractor: command not found
It was working fine a while ago, I've updated my npm and node to latest versions. I think after that the PATH variables messed up. Googled for a solution but didn't work anything. I don't want to mess up the current situation.
Current path is:
azim#azim-desktop:~$ echo $NODE_PATH
/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/azim/npm-global/lib/node_modules
Versions:
azim#azim-desktop:~$ npm --version
2.14.12
azim#azim-desktop:~$ node --version
v4.3.1
The environment variable $NODE_PATH is used by node to look for modules only.
Essentially you'll want to make sure that the directory path, where the protractor binary is located, is accessible through the environment variable $PATH instead.
Example of where my protractor is installed:
root#codeblog:~# which protractor /usr/bin/protractor
root#codeblog:~# env | grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
If you got protractor installed at another place then you might want to tweak your ~/.bashrc to append that directory into the $PATH variable.
Like:
PATH=$PATH:/usr/my_protractor_dir/bin

NodeJS module installers do not set PATH variable

For some reason on my current and previous pc, installing modules in NodeJS does not create PATH variables (Using windows 7/10). I managed to get the modules working in the past by manually editing my PATH variables, but it would be "cool" if NodeJS could do this for me...
I have just downloaded and installed NodeJS and Weinre again. npm gets added to the path variable, Weinre does not. (The same thing happend with Ionic a few weeks back, so had uninstalled it to try it again later).
I am running the command line prompt as an administrator.
Another thing which confuses me, which might be the cause of the problem is the following. I have installed NodeJS in:
C:\Program Files\nodejs"
But running "npm -g ls" gives me the following result:
C:\>npm -g ls
C:\Program Files\IBM\RAD9.1\cordova_cli
└─┬ weinre#2.0.0-pre-I0Z7U9OV
├─┬ express#2.5.11
│ ├─┬ connect#1.9.2
│ │ └── formidable#1.0.17
│ ├── mime#1.2.4
│ ├── mkdirp#0.3.0
│ └── qs#0.4.2
├─┬ nopt#3.0.4
│ └── abbrev#1.0.7
└── underscore#1.7.0
I have IBM Rational Application Developer installed, and it seems like NodeJS refers to this installation folder... :(
If the output of npm prefix -g matches C:\Program Files\IBM\RAD9.1\cordova_cli then everything is behaving as expected. You can either change your global npm prefix to your Node.js executable and reinstall the npm packages, or just add the current prefix to your PATH.
I would probably another clean reinstall of Node.js and npm. Before doing so, make sure to manually delete any existing npm modules and configs:
Run npm config ls -l, find the globalconfig line, and delete that file.
Go to the output directory of npm prefix -g and delete any node and node_modules files or directories.
Uninstall node as usual

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!

zsh: command not found: grunt-init

I'm new to gruntjs and am trying to get the grunt-init templates up and running however I constantly get this error: zsh: command not found: grunt-init
when I run the install it shows me all of this, so it seems like it is installing fine
→ npm install -g grunt-init
/Users/jsturgess/npm-global/bin/grunt-init -> /Users/jsturgess/npm-global/lib/node_modules/grunt-init/bin/grunt-init
grunt-init#0.3.2 /Users/jsturgess/npm-global/lib/node_modules/grunt-init
├── semver#1.0.14
├── colors#0.6.2
├── async#0.2.10
├── hooker#0.2.3
├── lodash#2.4.1
├── prompt#0.1.12 (async#0.1.22, pkginfo#0.3.0, winston#0.5.11)
└── grunt#0.4.5 (which#1.0.9, dateformat#1.0.2-1.2.3, eventemitter2#0.4.14, getobject#0.1.0, rimraf#2.2.8, async#0.1.22, grunt-legacy-util#0.2.0, exit#0.1.2, nopt#1.0.10, lodash#0.9.2, coffee-script#1.3.3, underscore.string#2.2.1, glob#3.1.21, iconv-lite#0.2.11, grunt-legacy-log#0.1.1, js-yaml#2.0.5, minimatch#0.2.14, findup-sync#0.1.3)
I've followed the grunt-init install directions and made the ~/.grunt-init/ directory and cloned the jquery template via the command the gave
git clone https://github.com/gruntjs/grunt-init-jquery.git ~/.grunt-init/jquery
What do I need to do to be able to use the grunt-init command?
Seems like you are using OhMyZsh. You need to add the Grunt files to your $PATH variable.
cd into your home directory and find this file .zshrc and look for the line with
export PATH=
and modify it like:
export PATH="path_to_grunt:$PATH"
the ':' serves as a delimiter for multiple paths.
What you are probably looking for is here:
export PATH="/usr/local/lib/node_modules/grunt-cli/bin/grunt:$PATH"
Fixed this problem by undoing the npm permission changes I had done from this article: https://docs.npmjs.com/getting-started/fixing-npm-permissions

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