Hello World in Node
Create a JavaScript file named "helloWorld.js"
Open your code editor and create a new file. Save this file with the name "helloWorld.js" in your project directory.
Write the Hello World program
Add the following code to your "helloWorld.js" file:
console.log('Hello, World!');
This code will print "Hello, World!" to the console when run.
Open your terminal or command prompt
Navigate to the directory where your "helloWorld.js" file is saved. You can do this by using the 'cd' command followed by the path to your project directory. For example:
cd path/to/your/project/directory
Make sure to replace "path/to/your/project/directory" with the actual path to your project directory.
Run the program
With your terminal or command prompt open and navigated to your project directory, run the program by typing the following command:
node helloWorld.js
Congratulations! You have just written and run your first Node.js program. Keep experimenting with more code and explore what Node.js has to offer.
Last updated
Was this helpful?