Your First Node Program
A first Node.js program prints a greeting. The program is a few lines of JavaScript.
Print a greeting
This line prints a greeting.
console.log("Hello, Node!");Print a number
This line prints the sum of 2 and 3.
console.log(2 + 3);Example
console.log("Hello, Node!");
console.log(2 + 3);
console.log("My first program runs.");Key points
- A program is a set of lines that a computer runs.
- console.log prints a value to the terminal.
- A string is text inside quote marks.
- Each line ends with a semicolon.
- Node.js runs the lines from top to bottom.
- The output is the text the program prints.
In this example, the first line prints Hello, Node!. The second line prints the sum of 2 and 3. The third line prints My first program runs.
Note
A missing quote mark stops the program with an error.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does console.log do?