Before we delve further into programming with JavaScript, you must set up a proper dev environment on your computer. Because in practice, programming involves much more than just printing messages using console.log()
. You will be working with variables, statements, functions, objects, and various other programming concepts.
As a result, we cannot rely solely on the browser's JavaScript console to execute such complex tasks. Instead, you'll need to install a JavaScript runtime on your machine.
A JavaScript runtime is a software environment in which JavaScript code can be executed. This environment provides JavaScript with components and libraries that allow the code to be executed outside of a web browser.
The most commonly used JavaScript runtime would be Node.js. An open-source JavaScript runtime that is built on top of the V8 JavaScript engine, which is taken directly out of Google Chrome.
It provides a set of built-in components that allow you to create web apps, command-line tools, and even mobile apps using JavaScript. It is also compatible with all the major operating systems, enabling you to run JavaScript code anywhere you want.
There are other alternatives to Node.js, such as Deno and Bun. They all claim to be faster than the old-school Node.js. Especially Bun, which has been getting a lot of attention recently, but since they are relatively new to the game, there might be some compatibility issues. So for the course, let's stick to Node.js.
Besides Node.js, we'll also need npm
, which stands for Node Package Manager. It is the default package manager for Node.js. It allows you to easily install, update, and manage third-party packages that can be used in your JavaScript project.
Depending on your operating system, there are many different ways to install Node.js and npm
. The easiest and most beginner-friendly method would be downloading the installer from the official website.
But as programmers, let's do things the programmer way and use the package manager that comes with the operating system. Open the terminal and run the following command.
If you are on macOS, use Homebrew.
1brew install node
If you are on Windows, use Winget.
1winget install --id=OpenJS.NodeJS -e
If you are using Linux or working on Windows Subsystem for Linux (WSL), use a package manager that works for your distribution. For further assistance, here is a complete reference on how to install Node.js.
These commands will install both Node.js and npm
on your computer. Verify your installation by running the following commands:
1node --version
1npm --version
Lastly, you should also make sure you have a code editor installed. A code editor offers highlighting and auto-completion features that will significantly improve your work efficiency. Visual Studio Code is a great option for beginners, and it's the most popular code editor out there. Simply download the appropriate installer for your operating system from their official website.