Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use npm with node.exe?

I have downloaded Windows Binary (.exe) of nodejs from the main page.

How can I install and use npm (Node package manager)?

like image 352
TN. Avatar asked Sep 04 '11 15:09

TN.


People also ask

How do I run npm in node JS?

The npm command is simple: npm install coffee-script -g . This will typically install the program and put a symlink to it in /usr/local/bin/ . This will then allow you to run the program from the console just like any other CLI tool.

Can I install node with npm?

Using a Node version manager to install Node. js and npm. Node version managers allow you to install and switch between multiple versions of Node. js and npm on your system so you can test your applications on multiple versions of npm to ensure they work for users on different versions.

Where can I find node EXE?

Some malware camouflages itself as node.exe which can be a security threat to your system. You can check if the file is located in the C:\Windows or C:\Windows\System32 folder, then it is a Trojan. The location for the legit file should be C:\Program Files or C:\Program Files (x86).

Where is npm EXE installed?

On most systems, this is /usr/local . On Windows, it's %AppData%\npm . On Unix systems, it's one level up, since node is typically installed at {prefix}/bin/node rather than {prefix}/node.exe .


2 Answers

The current windows installer from nodejs.org as of v0.6.11 (2012-02-20) will install NPM along with NodeJS.

NOTES:

  • At this point, the 64-bit version is your best bet
  • The install path for 32-bit node is "Program Files (x86)" in 64-bit windows.
  • You may also need to add quotes to the path statement in environment variables, this only seems to be in some cases that I've seen.
  • In Windows, the global install path is actually in your user's profile directory
    • %USERPROFILE%\AppData\Roaming\npm
    • %USERPROFILE%\AppData\Roaming\npm-cache
    • WARNING: If you're doing timed events or other automation as a different user, make sure you run npm install as that user. Some modules/utilities should be installed globally.
    • INSTALLER BUGS: You may have to create these directories or add the ...\npm directory to your users path yourself.

To change the "global" location for all users to a more appropriate shared global location %ALLUSERSPROFILE%\(npm|npm-cache) (do this as an administrator):

  • create an [NODE_INSTALL_PATH]\etc\ directory
    • this is needed before you try npm config --global ... actions
  • create the global (admin) location(s) for npm modules
    • C:\ProgramData\npm-cache - npm modules will go here
    • C:\ProgramData\npm - binary scripts for globally installed modules will go here
    • C:\ProgramData\npm\node_modules - globally installed modules will go here
    • set the permissions appropriately
      • administrators: modify
      • authenticated users: read/execute
  • Set global configuration settings (Administrator Command Prompt)
    • npm config --global set prefix "C:\ProgramData\npm"
    • npm config --global set cache "C:\ProgramData\npm-cache"
  • Add C:\ProgramData\npm to your System's Path environment variable

If you want to change your user's "global" location to %LOCALAPPDATA%\(npm|npm-cache) path instead:

  • Create the necessary directories
    • C:\Users\YOURNAME\AppData\Local\npm-cache - npm modules will go here
    • C:\Users\YOURNAME\AppData\Local\npm - binary scripts for installed modules will go here
    • C:\Users\YOURNAME\AppData\Local\npm\node_modules - globally installed modules will go here
  • Configure npm
    • npm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"
    • npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
  • Add the new npm path to your environment's PATH.
    • setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"

For beginners, some of the npm modules I've made the most use of are as follows.

  • axios - for more complex http posts/gets
  • isomorphic-fetch - for http(s) post/get requests
  • node-mailer - smtp client
  • mssql - interface and driver library for querying MS SQL Server (wraps tedious)

More advanced JS options...

  • async/await - async functions, supported via babel

For testing, I reach for the following tools...

  • mocha - testing framework
  • chai - assertion library, I like chai.expect
  • sinon - spies and stubs and shims
  • sinon-chai - extend chai with sinon's assertion tools
  • babel-istanbul - coverage reports
  • jest - parallel testing, assertions, mocking, coverage reports in one tool
  • babel-plugin-rewire - slightly easier for some mocking conditions vs. jest

Web tooling.

  • webpack - module bundler, package node-style modules for browser usage
  • babel - convert modern JS (ES2015+) syntax for your deployment environment.

If you build it...

  • shelljs - shell utilities for node scripts,. I used to use gulp/grunt, but these days will have a scripts directory that's referenced in package.json scripts via npm. You can use gulp tools inside plain scripts.
like image 107
Tracker1 Avatar answered Sep 25 '22 17:09

Tracker1


When Node.js is not installed using the msi installer, npm needs to be setup manually.

setting up npm

First, let's say we have the node.exe file located in the folder c:\nodejs. Now to setup npm-

  1. Download the latest npm release from GitHub (https://github.com/npm/npm/releases)
  2. Create folders c:\nodejs\node_modules and c:\nodejs\node_modules\npm
  3. Unzip the downloaded zip file in c:\nodejs\node_modules\npm folder
  4. Copy npm and npm.cmd files from c:\nodejs\node_modules\npm\bin to c:\nodejs folder

In order to test npm, open cmd.exe change working directory to c:\nodejs and type npm --version. You will see the version of npm if it is setup correctly.

Once setup is done, it can be used to install/uninstall packages locally or globally. For more information on using npm visit https://docs.npmjs.com/.

As the final step you can add node's folder path c:\nodejs to the path environment variable so that you don't have to specify full path when running node.exe and npm at command prompt.

like image 36
Ashish Uttam Avatar answered Sep 22 '22 17:09

Ashish Uttam