Key Takeaways
- Install a currently supported Node.js LTS release for a general-purpose JavaScript learning environment.
- Use the Node.js REPL to evaluate expressions immediately, without creating a web page or project.
- Save experiments in a JavaScript file when you want to keep and rerun them.
- You don't need Babel for the examples here, but Node.js doesn't supply browser objects such as document or window.
To practice JavaScript locally, install Node.js, open your terminal, and run node. Its interactive console lets you enter JavaScript and see the results immediately.
Node.js is a runtime: an environment that executes JavaScript outside the browser. It uses the V8 JavaScript engine and is useful for local scripts and command-line tools as well as backend applications.
ES6 means ECMAScript 2015, a specific edition of JavaScript—not a separate program you install. This setup works for ES6 practice and the newer JavaScript features your installed Node.js release supports; see the JavaScript ES6 introduction for the language background.
How to Install Node.js
Choose a supported LTS release
Start with the official Node.js download page and select the latest release labeled LTS. LTS means long-term support. Choose Current when you specifically want to explore newer runtime features, rather than simply because its version number is higher.
The Node.js release list identifies supported and end-of-life releases. Avoid installing an unsupported release just to match an old tutorial's output.
Pick an installation method for your operating system
A version manager lets you install and switch between Node.js versions without repeatedly replacing a system-wide installation. The npm installation guide recommends this approach; an official installer is also a straightforward option for a first sandbox.
| Operating system | Installation choices |
|---|---|
| Windows | Use the Windows installer from the Node.js download page, or use NVM for Windows to manage multiple versions. |
| macOS | Use the macOS installer from the Node.js download page, or install through nvm. |
| Linux | Use nvm, or follow the instructions for your platform on the Node.js download page. |
For an installer, select your operating system and matching processor architecture, download it, and complete the installation wizard. Then open a new terminal window.
If you choose nvm on macOS or Linux, complete its documented installation first. Once nvm is available in your shell, these commands install the latest LTS release and select it:
nvm install --lts
nvm use --ltsNVM for Windows is a separate project. Follow its own instructions rather than copying the macOS/Linux nvm commands.
Check that Node.js and npm are available
Open your terminal or Windows Command Prompt and run these commands, one at a time:
node --version
npm --versionEach command should print its installed version. The following lines are placeholders, not literal versions you need to match:
vX.Y.Z
X.Y.Znode -v is another way to check the Node.js version. npm is a package manager installed alongside Node.js by the official installer and the version-manager methods above; you don't need to install any packages for this tutorial.
Launch the Node.js REPL
In your terminal, enter:
nodeThis starts the Node.js REPL, short for Read-Eval-Print Loop. It reads your input, evaluates the JavaScript, prints a result, and waits for the next expression.
Write your first line of code
At the > prompt, type 2 + 2 and press Enter. Here is the interaction; the prompt and result are shown for context, not for you to type:
> 2 + 2
4
>Try an ES6 arrow function
Next, define and call a function:
> const double = n => n * 2;
undefined
> double(4)
8
>This uses an ES6 arrow function to double its input. The undefined after the declaration is normal REPL output, not an error. For more practice with declarations, see JavaScript ES6 variables.
Exit the console
Type .exit and press Enter to return to your terminal. According to the REPL command reference, Ctrl+C cancels current input; pressing it twice on a blank line exits. Ctrl+D is another exit shortcut, commonly used in Unix-like terminals.
Save and Run a JavaScript File
Use a file for code you want to keep. Create a folder for your experiments, then save the following in a plain-text file named hello.js:
console.log('Hello, JavaScript');Exit the REPL if it's still open. In your terminal, switch to the folder containing the file, then run the script with Node.js:
node hello.jsThe output is:
Hello, JavaScriptUnlike the REPL, running a file doesn't automatically print each expression's value. Use console.log() when you want visible output. You don't need a package manifest, build tool, or web server for this example.
Node.js Versus Browser JavaScript
The language is shared, but the surrounding APIs differ. As the Node.js browser comparison explains, Node.js doesn't provide document, window, or the DOM by default. The DOM is the browser's object representation of a web page.
Use Node.js for these language exercises and local scripts. Use a browser's developer console or JavaScript in a page's <script> element when you want to manipulate page elements. Node.js also supplies system APIs, such as filesystem access, that ordinary browser code doesn't expose in the same way.
Do You Need Babel for This Setup?
No. You can run these examples directly in a supported Node.js release. For newer features, check support against your installed runtime rather than assuming that every feature called “modern JavaScript” is available; Node.js documents this distinction in its JavaScript feature-support guide.
Babel becomes relevant when your project must target environments that lack the syntax you use. Its preset-env documentation distinguishes syntax transformations from polyfills: compatibility code that supplies missing built-in functionality. Transforming syntax alone doesn't provide every missing API, and Babel doesn't turn Node.js into a browser.
Troubleshooting Your Node.js Setup
- “node: command not found” or “node is not recognized”: Confirm the installation finished, then close and reopen your terminal. If it still fails, check the installer's or version manager's setup instructions, including PATH—the list of directories your shell searches for commands.
- Your version manager isn't available: Finish its shell-setup instructions before trying to install Node.js through it. Installing the manager and installing Node.js are separate steps.
- Your file won't run: Check that you're in the folder containing
hello.jsand that your editor didn't save it ashello.js.txt. - A terminal command fails inside the REPL: Enter
.exitfirst. Commands such asnode hello.jsbelong in your operating-system shell, not at Node's>prompt.
You now have two useful workflows: the REPL for quick questions and script files for repeatable experiments. Keep practicing the language, or move on to the Node.js and Express tutorial when you're ready to build a backend.
FAQ
How do I check that Node.js is installed?
Run node --version in your terminal; it should print the installed Node.js version. Run npm --version separately to confirm that npm is available too.
Should I install the LTS or Current version of Node.js?
Choose the latest supported LTS release for a general-purpose learning environment. Choose Current when you specifically want to explore newer runtime features.
How do I run a JavaScript file with Node.js?
Save your code in a file such as hello.js, then run node hello.js from the terminal in the same folder. Use console.log() to display results.
How do I exit the Node.js REPL?
Type .exit and press Enter. You can also press Ctrl+C twice on a blank line; Ctrl+D is another exit shortcut.
Do I need Babel to use modern JavaScript in Node.js?
No, not for syntax supported by your installed Node.js release. Babel is useful when you must target environments that lack required syntax, while missing APIs may need separate compatibility support.
Further Reading
- Official Node.js downloads — installation options for your platform.
- Node.js releases — LTS, Current, and end-of-life status.
- Installing Node.js and npm — installers and version-manager guidance.
- nvm documentation — installation and version switching on macOS and Linux.
- NVM for Windows documentation — Windows-specific version management.
- Node.js REPL reference — commands, keyboard shortcuts, and history.
- Node.js and browser differences — language versus runtime APIs.
- Babel preset-env documentation — target-based syntax transformations and polyfills.
