Hello World in Node

  1. Create a JavaScript file named "helloWorld.js"

  2. Open your code editor and create a new file. Save this file with the name "helloWorld.js" in your project directory.

  3. Write the Hello World program

  4. Add the following code to your "helloWorld.js" file:

  5. console.log('Hello, World!');

  6. This code will print "Hello, World!" to the console when run.

  7. Open your terminal or command prompt

  8. 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:

  9. cd path/to/your/project/directory

  10. Make sure to replace "path/to/your/project/directory" with the actual path to your project directory.

  11. Run the program

  12. With your terminal or command prompt open and navigated to your project directory, run the program by typing the following command:

  13. 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?