Chapter 3: Your First Node.js Application

In this chapter, you’ll write, run, and debug your first Node.js programs. To keep it simple, these won’t use any third-party modules or npm. They’re self-contained scripts that use the standard library provided in Node.js.

Your First Console App

Command-line console applications can be useful for automating tasks, formatting data, manipulating files, or any other laborious job that’s best handled by a computer.

Create a directory for your project, such as console:

mkdir console
cd console

Then add a file named hello.js with the following content:

#!/usr/bin/env node

// output message
console.log('Hello World!');

Save and run it from the command line:

node hello.js

You should now see Hello World! ...

Get Node.js: Novice to Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.