Nodejs NPM
Table of Content
Introduction
npm is the world's largest software registry (npm docs). it consists of three major components:
- the website to discover packages, set up profiles, and manage other aspects of your npm experience.
- The CLI runs from a terminal, and is how most developers interact with npm.
- The registry is a large public database of JavaScript software and the meta-information surrounding it.
Common package configuration
package that gets used among projects
easy exporting and importing
To get a better importing experience of the common package
(import {requireAuth} from "@maguas/common";
instead of import requireAuth from "@maguas/common/src/requireAuth";
)
the following is recommended:
- index.js with all files being exported
- add the main file property and the declarations property
- add this useful scripts to package.json
- set these properties in tsconfig.json
Favorite libraries
LERNA
A tool for managing JavaScript projects with multiple packages. lerna docs
lerna.json
package.json
PM2
PM2 is daemon process manager that will help you manage and keep
your application online. Getting started with PM2
is straightforward, it is offered as a simple
and intuitive CLI, installable via NPM. (pm2 docs)
- command used for executing a npm script
- command to log any pm2 application running
- command to monitor an application (memory usage)
Commander
Here is an example of how to use commander
package.json
tsconfig.json
./src/commands/serve
@maguastupaguas/local-api serve index.ts
Concurrently
Run multiple commands concurrently. Like npm run watch-js & npm run watch-less but better. (concurrently docs)
Ngrok
Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. (ngrok docs)
Expose a web server on port 80 of your local machine to the internet