Running your First NodeJS Program
There’s nothing like some practice! In this quick, 5-10 minute exercise, you’ll run your very first (and very simple) program using JavaScript and NodeJS.
At the end of this execise, you’ll know how to print your own unique message on your terminal, using one simple command!
-
Create your program file
First, create a test file. To do this, open the txt editor of choice (notepad in Windows, for example) and input the following code:
test.js console.log("Hello, fujin!"); -
Save your program
Now save the file as
test.jsin a location of your choice. These could be your desktop, for example, or any other regular folder. -
Navigate to the program folder
Use your terminal to navigate to the folder where you saved your
test.jsfile.If you’re struggling to move around using your terminal, you can check out our Terminal Navigation Practice for help figuring out where you are and moving across folders.
-
Run your program
In the program folder, type the command
nodefollowed by the name of the file you wish to run. If everything went well, “Hello, fujin!” will appear in your terminal.Terminal window node test.jsHello, fujin!
Congratulations! You have run your first JS script using Node!
With the extensive versatility that JavaScript and NodeJS bring to the table, it’s easy to get overwhelmed!
While you’re welcome to deepen your knowledge on either Node or JavaScript, we suggest you jump ahead into the next article and learn the magic of NPM, Node’s own package manager. This will allow you to access a new tutorial and tons of fun tools, including our go-to static site generator, Astro!