NPM

NPM#

NPM is a package manager for javascript. Check NPM for more details.


Consider the typical approach of using packages provided by the NPM. The following cell creates the /tmp/node_example folder and the package.json file within it.

The package.json file defines the npm environment, and all installed packages will be stored in this folder.

mkdir /tmp/node_example
cd /tmp/node_example
echo {} > package.json

Install the package by running the command npm install <package name>. The following cell installs cowsay:

npm install cowsay
(##################) ⠸ reify:strip-ansi: http fetch GET 200 https://registry.npistry.?25h
added 41 packages, and audited 42 packages in 2s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

The corresponding files must be created in the folder:

ls -la
total 52
drwxrwxr-x  3 user user  4096 wrz 17 16:04 .
drwxrwxrwt 24 root root 20480 wrz 17 16:04 ..
drwxrwxr-x 32 user user  4096 wrz 17 16:04 node_modules
-rw-rw-r--  1 user user    51 wrz 17 16:04 package.json
-rw-rw-r--  1 user user 15690 wrz 17 16:04 package-lock.json

The npm exec command allows you to run the package. The following code invokes the installed cowsay package:

npm exec cowsay "hello, npm!"
 _____________
< hello, npm! >
 -------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||