Globally installed npm package not accessible in terminal - node.js

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

Related

Update npm module, but showing different older version in my console window

I wanted to install the latest version of socket.io, and the latest ver seems to be 1.45.socket.io download
To do this, I just type the following command.
npm install socket.io
However, when I checked installed modules in my laptop, socket.io's version did not change as can be seen below.
YANAGISAWAYUMA-no-MacBook-Pro:~ yanagisawa_yuma$ npm list --depth=0
yanagisawa_yuma#0.0.0 /Users/yanagisawa_yuma
├── ar-drone#0.3.3 extraneous (git://github.com/felixge/node-ar-drone.git#228bd4573e765bed3861f259ce7e66fcace15f43)
├── express#4.9.0
├── gulp#3.9.0
├── node#0.0.0
├── node-osc#1.1.0 extraneous
├── node-static#0.7.3
├── socket.io#1.1.0
└── static#2.0.0
What am I missing?
Instead of simply npm install socket.io,
try npm install socket.io#version

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!

npm install not installing things at /usr/bin

I am trying to install SailsJS with:
$ sudo npm install -g sails
It works, install everything at /home/brunoluiz/npm/lib/node_modules/sails with the following log:
/home/brunoluiz/npm/bin/sails -> /home/brunoluiz/npm/lib/node_modules/sails/bin/sails.js
sails#0.9.16 /home/brunoluiz/npm/lib/node_modules/sails
├── connect-flash#0.1.1
├── pluralize#0.0.5
├── inflection#1.2.5
├── grunt-sails-linker#0.9.5
├── grunt-contrib-clean#0.4.1
├── node-uuid#1.4.0
├── async#0.2.9
├── grunt-contrib-concat#0.3.0
├── grunt-contrib-copy#0.4.1
├── grunt-contrib-coffee#0.7.0
├── ejs-locals#1.0.2
├── ejs#0.8.4
├── underscore.string#2.3.0
├── coffee-script#1.6.2
├── lodash#2.4.1
├── i18n#0.4.1 (debug#0.8.0, sprintf#0.1.3)
├── optimist#0.3.4 (wordwrap#0.0.2)
├── include-all#0.1.2 (underscore.string#2.3.1)
├── sails-disk#0.9.3 (waterline-criteria#0.9.7, lodash#2.3.0, fs-extra#0.8.1)
├── fs-extra#0.5.0 (jsonfile#0.0.1, ncp#0.2.7, mkdirp#0.3.5, rimraf#2.1.4)
├── connect-redis#1.4.5 (debug#0.8.0, redis#0.7.3)
├── grunt-contrib-jst#0.5.0 (lodash#1.0.1, grunt-lib-contrib#0.5.3)
├── glob#3.1.14 (inherits#1.0.0, graceful-fs#1.1.14, minimatch#0.2.14)
├── grunt-contrib-cssmin#0.6.1 (grunt-lib-contrib#0.6.1, clean-css#1.0.12)
├── grunt-cli#0.1.9 (resolve#0.3.1, nopt#1.0.10, findup-sync#0.1.3)
├── grunt-contrib-watch#0.4.4 (gaze#0.3.4, tiny-lr#0.0.4)
├── connect-mongo#0.3.2 (mongodb#1.2.14)
├── grunt-contrib-uglify#0.2.2 (grunt-lib-contrib#0.6.1, uglify-js#2.3.6)
├── waterline#0.9.16 (underscore#1.5.2, q#0.9.7, anchor#0.9.12)
├── grunt#0.4.1 (which#1.0.5, dateformat#1.0.2-1.2.3, eventemitter2#0.4.13, colors#0.6.2, hooker#0.2.3, async#0.1.22, nopt#1.0.10, minimatch#0.2.14, lodash#0.9.2, rimraf#2.0.3, coffee-script#1.3.3, underscore.string#2.2.1, iconv-lite#0.2.11, glob#3.1.21, findup-sync#0.1.3, js-yaml#2.0.5)
├── winston#0.7.1 (cycle#1.0.3, stack-trace#0.0.9, eyes#0.1.8, colors#0.6.2, pkginfo#0.3.0, request#2.16.6)
├── express#3.4.0 (methods#0.0.1, debug#0.8.0, range-parser#0.0.4, cookie-signature#1.0.1, fresh#0.2.0, buffer-crc32#0.2.1, cookie#0.1.0, mkdirp#0.3.5, commander#1.2.0, send#0.1.4, connect#2.9.0)
├── grunt-contrib-less#0.9.0 (grunt-lib-contrib#0.6.1, chalk#0.4.0, less#1.6.3)
└── socket.io#0.9.14 (base64id#0.1.0, policyfile#0.0.4, redis#0.7.3, socket.io-client#0.9.11)
The problem is when you try to use sails: you run sails new project, for example, and it doesn't find sails. Investigating a little bit, I discovered npm is not installing the modules at /usr/bin. Is there some reason for that? Some config?
The same is happening with Karma module.
I used the nodejs from ppa, created the symbolic link for node and installed npm from the official install.sh script (https://www.npmjs.org/install.sh).
It sounds like your npm installation is configured to use /home/brunoluiz/npm as prefix, meaning that it will place symlinks to the CLIs that come with globally installed packages in {prefix}/bin.
In a default installation, prefix is either /usr or /usr/local on Unix platforms (%APPDATA%/npm on Windows).
If {prefix}/bin is not in your $PATH, you won't be able to execute such CLIs just by name.
To see the current prefix value in effect, run:
npm get prefix
Your options are:
Add /home/brunoluiz/npm/bin to your $PATH
Change the value of the prefix configuration item to a folder whose bin subfolder is already in your $PATH; e.g.:
npm set prefix /usr # Ubuntu; CLI symlinks are placed in /usr/bin
npm set prefix /usr/local # OSX; CLIs symlinks are placed in /usr/local/bin
Note, however, that you'd then have to reinstall your global packages for the symlinks to be created in the new {prefix}\bin location.
In addition to mklement0's answer, the first solution (adding the npm binary directory path to the PATH variable) creates another problem when the commands are run with sudo prefix on Linux environment. To solve it, the npm binary directory path must also be added in secure_path in /etc/sudoers.tmp. Here is how:
Why can't sudo find a command after I added it to PATH?

Command not found when trying to run a nodeschool lesson

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

Resources