Let’s jump right in and create our first Node.js program.
If you don’t have a local projects folder yet, create a
dev folder in your home directory or on your desktop.
We’ll keep all the projects organized there.
In that folder, create a
first-node-app directory, and open it in VS Code.
Inside it, create a file named
This will be the main file of our program.
It actually does not matter how you name it. It could be called
app.js or whatever, like
index.js is common for the entry point of your program.
console.log('test') in the
index.js file, and save it.
Now open the terminal inside VS Code, using the menu Terminal → New Terminal
The program will execute and its output will be displayed in the terminal:
💁♂️ Note that the Node.js program we ran exited and returned control to the terminal (you can see there’s a new terminal prompt) because it executed all the lines we had, completed its job, and it quit. Some Node programs you write could be long-running, like servers that stay active until you terminate their execution manually.
But outside of it, as we’ll see, it can access the network, the filesystem, the database, configuration options, and a lot more.
Lessons this unit:
|1:||Installing Node.js on your computer|
|2:||▶︎ How to write your first Node.js program|
|3:||Importing other files|
|4:||Using npm to install packages|
|5:||Using built-in modules|