Register to get access to 15+ free programming courses with interactive exercises

Installing JavaScript JS: Setting up environment

To run JavaScript code, download and install Node.js.

The first option is to do this manually in one of the various ways described in the documentation.

The second option is to use the package manager. Open the terminal and run the installation command appropriate to your operating system:

Ubuntu or Ubuntu on Windows

# Install cURL, a console HTTP client, to download the node install script
sudo apt-get install curl
# Download and run the installer script to add and set up a repository in the package manager
curl -sL | sudo -E bash -
# You can now install Node.js via a package manager
sudo apt install -y nodejs


brew install nodejs

Interactive code execution

Now let's make sure that Node.js is installed and running. Some operating systems will probably require you to restart the terminal or even reboot.

Open the terminal and run the following command:

# The version you will see should be the same or higher than the one shown here.
# Otherwise, errors may occur.

node --version

If all goes well, it's time to run the JavaScript code.


Executing node will start REPL. This is an environment similar to the conventional terminal, but it uses JavaScript code instead of Bash commands. You can use it to type a piece of code and immediately execute it by pressing Enter.

> 1 + 5
6 # the result is immediately shown on the screen
> 7 % 2

This is very convenient to quickly check how something works, as well as for debugging and a few simple calculations. REPL can use variables and remembers previous ones input:

> a = 5
> b = 10
> a + b

There are several options to exit REPL:

  1. Type .exit and press Enter
  2. Press CTRL + C twice
  3. Press CTRL + D

This will bring you back into the normal shell.

Welcome to Node.js v16.4.1.
Type ".help" for more information.
> 1 + 5
(To exit, press ^C again or ^D or type .exit)

Keep the concept of Node.js REPL and shell (e.g. bash) separate: typing node runs a program that has nothing to do with the shell in which it is run. Any attempt to use this REPL as a normal shell will result in various syntax errors:

> cd ~
cd ~

SyntaxError: Unexpected token ~

Example of installing and running Node.js on Ubuntu

Running code from files

REPL is not suitable for full and convenient development, which is why the code is written in plain text files on the developer's computer. What editor should be used for this purpose? The most common and convenient code editor by far is VS Code. Download and install it, and explore its interface. It's got a lot of built-in features that can be extended with plug-ins.

Open the editor and create an index.js file with the following contents:

console.log("Hello, Hexlet!");

VS Code has built-in tools to run the code, but for now, while you're still learning, you should learn how to run code manually. Open a terminal in the directory where you created the file and run the following command:

# First go to the directory with the index.js file
node index.js
'Hello, Hexlet!'

Do it yourself

  1. Set up your operating system so that it's ready for Node.js
  2. Install Node.js
  3. Start the REPL and try to execute some JavaScript code
  4. Calculate Math.sqrt(256) + 100 in the REPL
  5. In the hexlet-js project, create an index.js file and add console.log('Hello, Hexlet!');
  6. Run this file with node index.js command, and make sure you see Hello, Hexlet! on the screen.

Recommended materials

  1. Installing Ubuntu on Windows
  2. Installing GIT on Windows
  3. Version Manager

Аватары экспертов Хекслета

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
hours of theory

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending the form, you agree to Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing:">Bookmate</span>
<span class="translation_missing" title="translation missing:">Healthsamurai</span>
<span class="translation_missing" title="translation missing:">Dualboot</span>
<span class="translation_missing" title="translation missing:">Abbyy</span>
Suggested learning programs

From zero to a developer. Refunds in case you won't get a job

Frontend Developer icon
Development of front-end components for web applications
start anytime 10 months

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending the form, you agree to Personal Policy and Service Conditions

Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.