Skip to Content
Efficient Node.js
book

Efficient Node.js

by Samer Buna
January 2025
Intermediate to advanced
240 pages
5h 26m
English
O'Reilly Media, Inc.
Content preview from Efficient Node.js

Chapter 2. Scripts and Modules

We used the node command briefly in Chapter 1 to explore Node’s REPL mode and execute simple scripts. In this chapter, we’ll learn how Node loads and executes scripts and modules. We’ll start by exploring more of the options, arguments, and environment variables that can be used with the node command, and learning more about what we can do in a REPL session. Then we’ll learn about the steps Node takes to load and execute a module.

Node CLI

The node command has many options that can be used to customize its behavior. It also supports arguments and environment variables to further customize what it does, and to pass data from the OS environment to Node’s process environment.

Let’s take a look. In the terminal, type the following:

$ node -h | less

This will output the help documentation for the command (one page at a time because we piped the output on the less command). I find it useful to always get familiar with the help pages for the commands I use often:

Usage: node [options] [ script.js ] [arguments] node inspect [options] [ script.js | host:port ] [arguments] Options: - script read from stdin (default if no file name is provided, interactive mode if a tty) -- indicate the end of node options --abort-on-uncaught-exception aborting instead of exiting causes a core file to be generated for analysis --build-snapshot Generate a snapshot blob when the process exits. Currently only supported in the node_mksnapshot binary. -c, --check syntax check script ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Node.js - The Complete Guide

Node.js - The Complete Guide

Academind by Maximilian Schwarzmüller GmbH
The Complete Node.js Developer Course (3rd Edition)

The Complete Node.js Developer Course (3rd Edition)

Andrew Mead, Codestars By Rob Percival
JavaScript from Beginner to Professional

JavaScript from Beginner to Professional

Laurence Lars Svekis, Maaike van Putten, Rob Percival, Codestars By Rob Percival
Node.js in Action, Second Edition

Node.js in Action, Second Edition

Nathan Rajlich, Marc Harter, Alex Young, TJ Holowaychuk, Tim Oxley, Bradley Meck, Mike Cantelon

Publisher Resources

ISBN: 9781098145187Errata Page