DevOps Tools/Repository Management/npm

From r00tedvw.com wiki
(Difference between revisions)
Jump to: navigation, search
(Local vs Global)
(Local vs Global)
Line 40: Line 40:
 
;Global
 
;Global
 
:installs the package in <code>{prefix}/lib/node_modules</code> which is owned by root (where <code>{prefix}</code> is usually <code>/usr/ or /usr/local/</code>.  A package should be installed globally when it provides an executable command that you run from the shell and is reused across projects.
 
:installs the package in <code>{prefix}/lib/node_modules</code> which is owned by root (where <code>{prefix}</code> is usually <code>/usr/ or /usr/local/</code>.  A package should be installed globally when it provides an executable command that you run from the shell and is reused across projects.
 +
'''NOTE:''' regarding global packages, you ''can'' use <code>npm config</code> to change the directory prefix to somewhere '''not''' owned by root, such as <code>$HOME</code>, however in most modern deployments you'll be using npm in an ephemeral container where the user is already root.  It should also be noted that most packages that are installed globally, like CLI, are used by the developer in a manual fashion rather than in an automated deployment.

Revision as of 17:18, 15 October 2019

npm

Contents

Overview

npm is the Node Package Manager. It provides access to a whole ecosystem of Node-based tools for developers to use when creating a server environment for applications or simply to aid them in local task automation. It is also commonly used with CI tools like Jenkins to automate build, test, prod, and other phases.

Installation

https://github.com/nodesource/distributions/blob/master/README.md

Ubuntu

~$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
~$ sudo apt-get install -y nodejs

CentOS

~$ sudo curl -sL https://rpm.nodesource.com/setup_12.x | bash -

Verify Installation

 ~$ which node
/usr/bin/node
~$ node --version
v12.11.1
~$ which npm
/usr/bin/npm
~$ npm --version
6.11.3

Make sure Node is working properly.

~$ node
Welcome to Node.js v12.11.1.
Type ".help" for more information.
> console.log('Node is running')
Node is running
undefined
> .exit

Update

CentOS

~$ npm install npm@latest -g

Node Modules

Local vs Global

Local
installs the package in a node_modules in your parent working directory. In general, all packages should be installed locally. This allows you to have dozens of the same applications on your computer, all running a different version of each package if needed.
Global
installs the package in {prefix}/lib/node_modules which is owned by root (where {prefix} is usually /usr/ or /usr/local/. A package should be installed globally when it provides an executable command that you run from the shell and is reused across projects.

NOTE: regarding global packages, you can use npm config to change the directory prefix to somewhere not owned by root, such as $HOME, however in most modern deployments you'll be using npm in an ephemeral container where the user is already root. It should also be noted that most packages that are installed globally, like CLI, are used by the developer in a manual fashion rather than in an automated deployment.

Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
OwnCloud
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
Plex Media Server
MetaSploit
Zoneminder
ShinobiCE
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
2020 Election
Volkswagen
Covid
NCDMV
Toolbox