So I can run a js file like
$ node file.js
with node.io inside the file doing things.
but if i go to the command line and try to type in a built in module like it shows at https://www.npmjs.org/package/node.io
$ node.io query "http://www.reddit.com/" a.title
I just get back -bash: node.io: command not found
This is probably something incredibly stupid, but I can't figure it out.
This just means that node.io is not installed or if installed is not available in $PATH.
You can install it using the following command.
$ npm install -g node.io
Related
When I run sudo npm install -g express-generator:
/Users/myname/npm/bin/express -> /Users/myname/npm/lib/node_modules/express-generator/bin/express-cli.js
/Users/myname/npm/lib
└── express-generator#4.15.5
And when I run express:
express not found
Also, I thought it was interesting that when I run which npm:
/usr/local/bin/npm
That is the path.
It seems that whenever I try to install something like yeoman or this express generator globally, it never works.
It should also be noted that I am on an Mac running zsh.
Most likely your npm bin directory is not in the path. Try to list the files in that directory by ls -l /usr/local/share/npm/bin/.
If you find the express file, you can add that directory to the path by export PATH=/usr/local/share/npm/bin:$PATH. If not, most likely something went wrong with your installation and you can try installing the module again.
Running this in the command line:
export PATH=/usr/local/bin/npm:$PATH
Fixed the issue...for now. I'm not totally sure why that worked.
This affects Homebrew users using Node.js & npm
When you install Node.js using Homebrew it does not put npm on the PATH for you, however it suggests that you should do so.
Homebrew doesn't modify the user's environment or dotfiles. However, brew install node does print a message suggesting the user add that path to their PATH.
Source
I'm trying to create a command line tool with node (following these instructions).
So I add "bin" to package.json file
"bin": {
"test": "./index.js"
}
Created index.js file
#!usr/bin/env node
console.log('test');
And I use $ sudo npm link.
Finally I try to run it via terminal but I'm getting -bash: /usr/local/bin/test: usr/bin/env: bad interpreter: No such file or directory
Any ideas anyone?
I don't think npm link is needed in this case; you normally would use it to connect a module from your file system that you might otherwise pull in via the npm install command.
Your shebang syntax looks off to me, though, missing the leading slash:
#!/usr/bin/env node
npm link links the module locally. For your bin, it means that the binary is installed into node_modules/.bin/ (if i recall fine).
To link a package globally, you should use the --local arg.
npm link . --local
I'm trying to setup babel on Ubuntu 14.04 but it doesn't seem to be working!
Here are some outputs that may be required:
$ which node
/usr/sbin/node
$ which nodejs
/usr/bin/nodejs
$ which babel
/usr/local/bin/babel
$ which babel-node
/usr/local/bin/babel-node
When I execute babel or babel-node the prompt just returns. The same happens on executing the commands with a filename as argument. (The file has just console.log("hello").
How do I fix this?
The /usr/sbin/node vs /usr/bin/nodejs issue has been covered in Cannot install packages using node package manager in Ubuntu but basically Ubuntu has a separate node package that is NOT Node.js. The package for Node.js on Ubuntu is called nodejs. If you have both installed, it means your scripts will try to run using the other unrelated application. One option is to symlink nodejs to node.
The best solution however would be to use something like nvm to install node for your user without installing it globally. Then you can install and update node versions extremely easily, and your PATH will always reference node properly.
Changing node to nodejs in the first line of /usr/local/bin/babel-node and /usr/local/bin/babel solves it.
I'm trying to update node (on Ubuntu) and have been using the n package to do this.
I've run the following:
$ sudo npm install -g n
% sudo n 0.10.21
This appeared to run OK, but now I get the following:
$ which node
/usr/local/bin/node
$ node -v
0.6.4
$ /usr/local/bin/node -v
0.10.4
which is baffling to me.
How can I get rid of 0.6.4 and ensure that 0.10.4 is what runs when I type node?
This is actually a shell issue. I've only seen it in bash, but here goes:
Bash caches where it has found commands in the past. This means that if you place an executable (with the same name as something you've run before) earlier in the PATH, which will correctly find the new one, but bash will hit the cache and run the old one.
The easiest fix is simply to close your shell and open a new one. However, you can aldo use the command hash -d node to clear node from the cache (or type node to see whether it is in the cache and what it is pointing to).
So that I don't have to keep restarting node.js during development I'm trying to use node-dev. Unfortunately, when I try to run node-dev from terminal I receive the error:
$ node-dev server.js
-bash: node-dev: command not found
I have globally installed node-dev via the npm install node-dev -g command. The output from this command is:
npm http GET https://registry.npmjs.org/node-dev
npm http 304 https://registry.npmjs.org/node-dev
npm http GET https://registry.npmjs.org/growl
npm http 304 https://registry.npmjs.org/growl
/usr/local/share/npm/bin/node-dev -> /usr/local/share/npm/lib/node_modules/node-dev/node-dev
node-dev#0.2.9 /usr/local/share/npm/lib/node_modules/node-dev
└── growl#1.6.1
To be sure node-dev is installed globally I've run npm ls -g which returns:
/usr/local/share/npm/lib
└─┬ node-dev#0.2.9
└── growl#1.6.1
Some other posts have indicated that my globally installed npm modules should be in the /usr/local/lib/node_modules folder instead of /usr/local/share/npm/lib/. I can't tell if this is for older versions of npm or something that actually matters.
I'm new to both Mac OS X and Node development so it wouldn't surprise me that I was overlooking something trivial. What haven't I done which is causing me to get a "command not found" error when trying to utilize node-dev? Is there some sort of $PATH environment issue I'm overlooking?
One note I don't have Growl installed but the node-dev documentation indicated it was optional.
I think this could be your issue, and here's a walk-through to fixing it. It's specifically for WebStorm & Mocha, but seems like it could be related. I think you may need to setup an alias.
env: node: No such file or directory
Reason for this is that when running GUI applications under MacOSX,
the environment variables are not the same as those when you run a
from a terminal. In particular, node for instance is not on the path.
To overcome this issue, you can either launch WebStorm from the
terminal (yuck!) or solve it. Fortunately this isn’t as hard as it
once was. Here’s a Tip on our forum for RubyMine but it applies to all
IDE’s including WebStorm. In essence, its creating an
environment.plist file inside ~/.MacOSX which contains your full path.
Mine is here if you want to download it. Make sure you reboot your
machine after doing this step.
Setting up an alias
Everything should be working now, but instead of
having to type this in each time, lets set up an alias for it in
WebStorm. Click on Preferences (CMD+, under MacOSX) and type in
Command to get to the command line tools. Click on the + button to
create a new entry and confirm the dialog box to create a new custom
framework.