0
0
Node.jsframework~15 mins

Running scripts with node command in Node.js - Mini Project: Build & Apply

Choose your learning style9 modes available
Running scripts with node command
📖 Scenario: You want to run a simple JavaScript file using Node.js on your computer. This is useful when you write scripts that do tasks like calculations or file operations without a web browser.
🎯 Goal: Learn how to create a basic JavaScript file and run it using the node command in the terminal.
📋 What You'll Learn
Create a JavaScript file named hello.js with a simple message.
Add a variable to hold a greeting message.
Write a line to display the greeting message using console.log.
Run the script using the node hello.js command.
💡 Why This Matters
🌍 Real World
Running JavaScript files with Node.js is common for backend development, automation scripts, and tools that do not need a browser.
💼 Career
Understanding how to run scripts with Node.js is essential for developers working with server-side JavaScript or command-line tools.
Progress0 / 4 steps
1
Create a JavaScript file with a greeting message
Create a file named hello.js and inside it, create a variable called greeting and set it to the string "Hello, Node.js!".
Node.js
Need a hint?

Use const to create a variable that does not change.

2
Add a console.log to show the greeting
Add a line that uses console.log to display the value of the greeting variable.
Node.js
Need a hint?

Use console.log(greeting); to print the message to the terminal.

3
Open your terminal and navigate to the file location
Open your terminal or command prompt and change directory to where hello.js is saved using the cd command.
Node.js
Need a hint?

Use cd followed by the folder path to reach your file location.

4
Run the script using the node command
In the terminal, run the command node hello.js to execute your script and see the greeting message printed.
Node.js
Need a hint?

Type node hello.js exactly to run your script.