One of the very first programs you can write to make sure your Node version works is the “Hello World” program. There are two ways to create the program: in the terminal or in your code editor of choice (i.e. Visual Studio Code, Vim, etc.). Make sure you have Node installed on your machine to get started.
1.In your terminal, type
node to start Node.
2.Input console.log(“Hello World”) into the Interpreter and hit enter.
3.Hello World will show up on the next line! Don’t worry if it says “undefined” in the following line. That just means we haven’t returned anything from a function.
4.If you would like to create a function to test, you can do that too! Here’s how to do that in the terminal:
Node will store the function in memory. If you want to run it, just type
helloWorld() in the terminal and hit enter. It’ll return Hello World! in the console.
Code Editor (i.e. Visual Studio Code)
- Open up your editor of choice and create a new file and save it as hello.js.
- In your file, input console.log(“Hello World”) into the file and save it.
- In your terminal, navigate to the directory/folder you saved your file. Use cd and ls to navigate from directory to directory.
- Use node hello.js to run the file. Hello World should show up on the next line.
- If you are using VS Code, the “play” button in the upper right hand corner will also run the current file and show the output on the lower half of the screen.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.