Skip to main content

JavaScript in Node.js

In this section, we will only talk about how to check if Node is installed on your computer and how to run JavaScript code in Node.js.

The first thing you need to do is to check if Node.js is installed on your computer. To do this, open your terminal and run the following command:

node -v

It should display the version of Node.js installed on your computer. If you see a version number, it means Node.js is installed. If you see an error message, it means Node.js is not installed, and you need to install it. I have taken the time to write a guide on how to install Node.js on your computer. You can check it in the previous section.

Run JavaScript in Node.js

To run JavaScript code in Node.js, create a new file with a .js extension and write your JavaScript code in it. For example, create a file named app.js and write the following code in it:

app.js
console.log("Hello, World!");

To run the JavaScript code in the app.js file, open your terminal and navigate to the directory where the file is located. Then run the following command:

node app.js

This is how your result should look like

Congratulations! You have successfully run JavaScript code in Node.js. You are now ready to write, run, and debug JavaScript code in Node.js. We keep going 🚀

In this course, we would not be focusing on how to write JavaScript code in Node.js. We would be focusing on how JavaScript works in the browser. If you are interested in learning how to write JavaScript code in Node.js, you can check out the Knownode docs.

Made with ❤️ by Fasakin Henry