CodeBlanks Logo Icon CodeBlanks

Summary - Node.js basics

Combine import, package.json and console.log to write your first Node.js program.

Summary - Node.js basics

In this group you saw the basics of Node.js: running files with the node command, writing output with console.log, sharing code with ES modules, managing projects with package.json and the difference between CommonJS and ESM.

Now there are two small tasks that bring these together. First a greeting message, then a two-line output.

Ready? Let us start.

Practice Write a greeting

Write two console.log calls: the first prints Node.js is running, the second prints Version 22.

Starter code

index.js
// Write two greeting lines

Sample solution

index.js
console.log("Node.js is running");
console.log("Version 22");

Expected output

Node.js is running
Version 22

Practice Two-line output

Assign the string "calculator" to a variable named app. Then call console.log with app; on the next line call console.log with "v1.0".

Starter code

index.js
// Define app and print two lines

Sample solution

index.js
const app = "calculator";
console.log(app);
console.log("v1.0");

Expected output

calculator
v1.0

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Program skeleton

Question
____("Node.js ready");
Answer
console.log("Node.js ready");

Explanation: We start with console.log.

2 Match the section concepts

Term Meaning
node Run command
console.log Output writing
import ESM import
package.json Project info

All lessons in Beginner