All notes


To quit node.js, from SO: how to exit in node.js:



REPL: A Read–Eval–Print Loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise. wikipedia: REPL.

Environment variables


When your Node.js process boots up it will automatically provide access to all existing environment variables by creating an "env" object as property of the process global object. If you want to take a peek at the object run the the Node.js REPL with node in your command-line and type:

console.log('The value of PORT is:', process.env.PORT);

PORTP=9999 node server.js

NODE_ENV=production node dotenv-example.js


// npm install dotenv --save

if (process.env.NODE_ENV !== 'production') {
  require('dotenv').load(); // This code will automatically load the .env file in the root of your project and initialize the values. It will skip any variables that already have been set.

inspect, debugger

Debugging debugging getting started.

When started with the "--inspect" switch, a Node.js process listens via WebSockets for diagnostic commands as defined by the Inspector Protocol, by default at host and port Each process is also assigned a unique UUID (e.g. 0f2c936f-b1cd-4ac9-aab3-f63b0f33d55e). The full URL is ws://

Inspector also includes an HTTP endpoint to serve metadata about the debuggee, including its WebSocket URL, UUID, and Chrome DevTools URL: http://localhost:9229/json/list.

Chrome DevTools 55+

Option 1: Open chrome://inspect in a Chromium-based browser. Click the Configure button and ensure your target host and port are listed.
Option 2: Copy the devtoolsFrontendUrl from the output of /json/list (see above) or the --inspect hint text and paste into Chrome.
Option 3: Install the Chrome Extension NIM (Node Inspector Manager)

Commands debugger.

# Yes, just use the name "myscript.js"
node inspect myscript.js
< Debugger listening on ws://
< For help see
< Debugger attached.
Break on start in myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
  2 setTimeout(() => {
  3   console.log('world');

# Or
node-inspector myscript.js