# Make a local npm package usable globally
npm link
## Unlink a package (same as running: npm install -g <pkg_name>)
npm uninstall -g <pkg_name>
# Check if user is logged into npm
npm whoami
# Create a nested directory tree
mkdir -p /path/to/dir
# Change ownership of directory tree to current user
sudo chown -R $(whoami) /path/to/dir
# Make a file executable by current user
sudo chmod +X /path/to/file
- Comming the changes that are meant to be released (RELEASE: x.x.x).
- Run
npm version major|minor|patch 'RELEASE x.x.x
. - Run
npm publish
.
At the top level of the file define:
process.on('unhandledRejection', () => {
// ...do something
});
We can use the global process
which is just an instance of an EventEmitter
so
we can use .on
to listen for events.
process.on('exit', () => {
//...logic
});
process.on('exit', () => {
//...logic
});
// Node best practice is to set the exit code on process to 1 (Fatal Execution Error)
process.exitCode = 1;
Despite JS being single threaded, the Event Loop allows Node to have non-blocking IO operations by offoading a lot of the work to the os kernel.
TODO(SW): See talk about the Node Event Loop by Bert Belder:
Global that gives use control over the currently running in Node
// Prints the current working directory of the Node process
process.cwd()
// Variables defined in the Node process
process.env
Standard input, output and error are channels for communicating between the terminal and a process.
To send the standard input of a process to the standard error:
process.stdin.pipe(process.stdout);
Give the process a reference to the array containing the inputs passed into a program.
The first 2 elements of process.argv
are always the executable responsible for running the process
and the path of the file being executed.
// To obtain arguments passed to the program
let args = process.argv.slice(2);