npm comes with node now. What does this mean? - node.js

Node noob here.
I had previously installed both npm and node separately.
Apparently, npm comes with node now. (link)
To my newbie mind, this means my previous dual installation is old and ugly. 1 binary > 2 binaries. So i uninstalled both.
Then I installed the latest node following the procedure. (i am running eOS)
Terminal
user#box:-$ which node
/usr/bin/node
user#box:-$ node -v
v0.10.22
user#box:-$ which npm
user#box:-$ npm -v
bash: /usr/bin/npm: No such file or directory
I can always run:
curl https://npmjs.org/install.sh | sh
but that seems to indicate that npm is actually NOT included in node.
When they say they are included do they just mean the code is in the same repo, but the binaries are still different?
Final question I have /usr/bin/node as well as /usr/bin/nodejs
can i delete one of these? im not sure when/where i picked up a second copy.

Yes, the nodejs package includes both node and npm executables. The code for each has its own repo, but when packaged both are included.
npm source: https://github.com/isaacs/npm
node source: https://github.com/joyent/node
When you install that .deb file from the PPA, you should get both /usr/bin/nodejs and /usr/bin/npm and 2 symlinks at /usr/bin/node (which points to) /etc/alternatives/node (which points to /usr/bin/nodejs).
If any of this isn't true, your install didn't fully succeed, most likely due to conflicting files you left around from your manual install. I would suggest uninstalling the .deb then making sure there are no stale files left from your manual install and then installing again.

Only node.js packages comes with npm. so if you are installing using an .msi, .exe, .dmg .pkg, .deb or using a package installer like apt-get, yum or brew, then you'll have both node and npm.
However,npm is not part of the node core. if you are installing node and using a method where you are using ./configure or make install || make link, then npm will not be installed, and will need to be compiled using the same type of installation, and node will have to be placed on your path.
If you used git, or unzipped node and you can see a configure script, then you will also need to acquire npm.

I've had issues (mostly on Mac) with npm ending up in directories that aren't in the terminal PATH. If you can figure out where npm is located, you can just add it to your path with something like:
export PATH=$PATH:/path/to/npm
I think (I'm not on a mac so I can't check at the moment) that it sometimes gets put in /usr/local/share/. But at any rate, the problem is likely NOT that npm isn't installed, but that it's installed somewhere you're not expecting.

Few months ago i had started learning the react so all this stuff i needed to install my laptop that had the ubuntu operating system.
What i did -- First i installed the node and without knowing that it came up with the npm package. I installed the npm package again.. but there was no conflict at all.
But after exploring all these things that nodejs have npm package. So i uninstalled the npm package due to concern about memory usage..
And Now everything is working fine....

Related

Homebrew/Node.js showing up though not installed

When I do find . -name "node*" from my root directory, I get:
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node_exporter.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodeenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-sass.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#14.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#10.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodebrew.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#12.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#16.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-build.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#18.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/nodejs
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node#19
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node.js
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodeclipse.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodebox.rb
./usr/local/Homebrew/Library/Homebrew/rubocops/cask/extend/node.rb
./usr/local/Homebrew/Library/Homebrew/test/language/node_spec.rb
./usr/local/Homebrew/Library/Homebrew/language/node.rb
but brew ls doesn't show node and node -v and npm show that the commands are not installed on PATH? What's going on here?
I went through the process of
I went through the process of removing all traces of Node and npm from my own installation as npm was corrupted (was mishandling vulnerabilities), and now want to install it using brew, or in some other way so all the errors with npm when attempting to npm install don't occur. Why does brew have node installed even though I didn't install it?
Those files are not NodeJS itself, but are the instructions that tell Homebrew how to install NodeJS. You can remove those formula (along with any others that are not being used) with brew cleanup.
Edit: You cannot actually remove the formulae since those are needed if you were to install it at a later point.

How to delete node installed by brew completely?

I have a problem with uninstalling 'node' with brew.
When I used
brew uninstall node
, it showed:
Uninstalling /usr/local/Cellar/node/7.8.0... (3,076 files, 39.9MB)
; but when I commanded:
node -v
, there is still
v6.9.4
When I tried to use brew uninstall node again, it showed:
Error: No such keg: /usr/local/Cellar/node
I think I installed node package before, and today I used a wrong command:
brew install nodejs
while I actually wanted to install node. And then I found I was wrong, so I also uninstalled nodejs in the same way. But node package with lower version is still there. Anybody knows why and can help me delete it completely and reinstall?
Sounds like you may have installed node via another method in the past.
If you do
$ ls -la $(which node)
It should tell you where it's installed (and if that's symlinked to another location or not).
Removing that binary is part of the thing, the other thing you'll want to do is remove the root npm and the node_modules folder.
Find npm the same way as you found the node binary, but the root node_modules folder is probably either under /usr/local/lib but might be elsewhere; you can check npm config ls -l to get a list of all the settings of npm, which will tell you what directories to look in are.

Global Node Packages Installed to Wrong Directory

I'm trying to install Hexo globally using npm. When I run
npm install -g hexo-cli
I'm informed that it was installed to /Users/myusername/.node/bin/hexo -> /Users/myusername/.node/lib/node_modules/hexo-cli/bin/hexo
The problem comes in when I run hexo init blog and the hexo command is not found.
I installed Node and npm with Homebrew, so when I run which node and which npm, the results are /usr/local/bin/node and /usr/local/bin/npm respectively.
I'm thinking that I still have leftover files and directories from when I installed Node without homebrew, but I don't want to start deleting things without fully knowing the repercussions. Would I be safe to delete all files located in the /Users/myusername/.node/ directory? I can't figure out why npm is not installing to the proper directory.
After a little digging, I found that my npm prefix variable was pointing do the wrong directory, left behind by the old Node installation. I ran npm config get prefix to see where it was pointing.
I set the new prefix value using npm config set prefix /usr/local. Homebrew is symlinked with this directory via /usr/local/bin. I uninstalled hexo-cli and reinstalled through npm, and now it works perfectly.
For NVM users
Run nvm use --delete-prefix v10.13.0 --silent replacing v10.13.0 with whatever version of node you're using.
A simple way to cope with environment variables/path problems on Windows:
Run command:
npm install -g hexo
Using node.js command prompt rather than cmd windows provided by Windows itself.

npm hangs on postinstall / unlock

I have a Linux server that runs some virtual Machines using KVM. Host machine is a Debian derivate with kernel 2.6.32-32(-pve).
In roughly 75% of the times I run npm install, it hangs while installing modules. I ran it in silly debug level and it always hangs at the line
npm info postinstall [module name] (older npm versions)
or
npm verb unlock done using [...] (newer npm versions)
forever.
It happens in every project on the host machine and on the virtualized systems for every node and every npm version I have tested (a lot, including the newest ones (2.7.x atm)).
It also is not deterministic. Sometimes it works, sometimes not and most of the times it hangs on a different module.
On my dev machine (which is in the same network, running OS X 10.10) it works fine.
I am not behind any kind of proxy.
What could possibly be wrong here?
EDIT: For the time being I solved this problem by checking in all my dependencies as gzipped files using https://github.com/JamieMason/shrinkpack
I was having the same issue for several hours, and couldn't work out what the problem was. I tried re-installing everything a few times, manually installing individual modules, switching from x64 to x86 versions of NodeJS, etc, and got nowhere.
In the end, I changed networks, from WiFi over ADSL2+ [~2mbps] to 4G Hotspot [~20mbps] and it worked in 30 seconds. No idea why, since it didn't seem like a network speed issue, but it solved the problem.
Hope this helps someone else, too!
I had the same problem on our Jenkins slaves based on Ubuntu, and it was solved by upgrading npm.
Default npm installed by apt-get has version 1.3.10 now, which is very old (shown by npm --version). There are at least two ways to upgrade it:
Run sudo npm install -g npm command. If you want to install a specific version you can run append it at the end of command: sudo npm install -g npm#2.1.3.
Or you could add NodeSource repositories using these instructions and run usual sudo apt-get update.
I have the same problem on Windows. I deleted my npm-cache folder and reinstalled npm. Everything started working normally after that.
The npm-cache folder can be found at
<your-drive>\Users\<your-name>\AppData\Roaming\npm-cache
Remember to turn on 'View hidden files because the AppData folder by default is hidden
You can reinstall npm by using the command,
npm i npm -g
On Windows make sure you are in a native CMD (not in VSCODE or whatever IDE). Also, try increasing the max memory limit for node:
set NODE_OPTIONS=--max_old_space_size=8096
I did the same, switched my network from WiFi to 3G and it worked.
I'm experiencing the same problem, this is the issue on Github:
https://github.com/npm/npm/issues/7862
There are some useful tips that seemed to help a few people.
For me doing $ npm install -g node-gyp (as suggested here: http://gangmax.me/blog/2013/05/13/resolve-npm-update-node-gyp-hung-problem/) fixed the problem.
I had the same problem and just run
npm cache clean
And it works!
Had this same problem in Windows. The solution was to restart after installing node and npm and then run command prompt as administrator.
In my case, a system restart did the work.
I ran npm install --verbose which suggested some lock on a file in npm-cache. And I think the system released the file (which was under use) after the system restart. I am using windows.
Try cloning the project again and then run npm install to install the packages in your terminal.
I ran into this with npm v6, and it turned out I was just being impatient. I just needed to wait a little longer and it proceeded to the next step.
npm cache clean --force
works for me :)
=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.
you can change temporary :
npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2
Run the your command to install your package .
open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
copy your package file CMD to parent folder "npm"
copy your package folder to parent folder "node_modules"
now run npm config set prefix C:\Users[username]\AppData\Roaming\npm
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm
now package working correctly with Command line

NPM appears to do nothing on Linux Mint 15

searched, and did not see this specific problem.
Trying to get a MEAN stack built on my Linux Mint machine, and bumping into a bit of an unusual issue.
Got MongoDB installed, and finally got it running correctly (none of the instructions ANYWHERE mentioned having to create the /data/db/ directory and set permissions, go figure).... it works now.
Got NodeJS installed, and it appears to work correctly.
I had been told (apparently incorrectly) that NPM installs right alongside Node, with:
sudo apt-get install nodejs
but:
$ npm
bash: /usr/bin/npm: No such file or directory
So I go ahead and install NPM separately.
$ sudo apt-get install npm
Seems to work, so far, no errors, and it looks like it is pulling down the NPM package and installing it...
$ nodejs -v
v0.10.21
$ npm -v
$
?? It simply fails to respond without any error... so I try:
$ npm install grunt -g --save-dev
$
Same completely silent failure... in fact, NOTHING I could do gets a response out of NPM.
Looked all over the web, and saw nothing similar anywhere... found out that NPM holds its cache files in ~/.npm and noticed that this folder didn't exist (kinda like the mongo issue above), so I created it, and set permissions to 7777... still nothing.
Purged and re-installed both node and npm, tried installing them both together and separately (yes, desperation)... still no love.
WTF am I doing wrong?
I would love, eventually, to have a nice development environment setup, hopefully with Cloud9 as a local IDE.... but already pulling my hair out.
=========================================================================================
OK, after a few more headaches, this is up and built now... thank you all.
Would love to mark both as answers, but it won't let me.
npm does come with node. Where is apt-get pulling it from? I install the Mac OS X packages on my Mac for development and npm does in fact come with it. I compile from source on my CentOS server and npm comes with it.
Your package provider may be providing them separately as a (in)convenience to you.
As for why your npm command does not work after installation, I can't say for sure, but I am suspicious of your use of --save-dev and -g together.
-g means to install globally, which means 2 things:
It will be installed outside of your npm package's structure into a system location like /usr/bin or /usr/local/bin
It requires root access to install. Did you use sudo to run it with root access?
Both of those requirements conflict with --save-dev which records the package as a dependency in your package.json file so that future npm install commands will install that package within the project space.
That said, I happen to know a lot about grunt. It has 2 parts, a globally installed tool and the package-specific tool. The correct way to install it is:
$ [sudo] npm install -g grunt-cli
$ npm install grunt --save-dev
This will install the grunt-cli package into a system location guaranteed to be in the $PATH, which turns around and looks for a package-specific grunt installed which is not system-wide.
When installing nodejs with npm, this one-liner worked for me.
sudo apt-get install nodejs nodejs-dev npm
I don't believe npm comes with the nodejs installation in the apt repo. Try to install npm separately using the following tutorial http://www.giantflyingsaucer.com/blog/?p=1688 'To install NPM ....'
====== Edit ====
node and npm IS separate. Follow the official wiki and everything should be fine

Resources