100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
JavaScript

Setting Up a JavaScript Environment

Step-by-step guidance on installing Node.js, choosing an editor, and running your first JavaScript file from the command line.

Introduction to JavaScriptBeginner8 min readJul 8, 2026
Analogies

1. Introduction

Before writing JavaScript programs, you need a way to run them. The simplest environment is any modern web browser, which has a built-in JavaScript engine accessible through the Developer Console. For more serious development, most developers install Node.js, a JavaScript runtime that lets you run .js files directly from the command line, outside a browser.

🏏

Cricket analogy: The browser console is like a quick net session in your backyard to test a technique, while Node.js is like joining a proper academy — a dedicated setup where you can run full practice sessions (.js files) outside the casual backyard (browser) environment.

A typical setup also includes a code editor (such as Visual Studio Code) and, for larger projects, a package manager like npm (bundled with Node.js) to install and manage third-party libraries.

🏏

Cricket analogy: A code editor like VS Code is your training kit, and for a full squad-level operation you also need npm, the equipment manager bundled with Node.js, to source and manage third-party gear (libraries) instead of making everything yourself.

2. Syntax

javascript
// hello.js
console.log("Hello from Node.js!");

// Run it from a terminal with:
// node hello.js

// Check installed versions:
// node --version
// npm --version

3. Explanation

To set up a basic JavaScript environment: (1) download and install Node.js from nodejs.org, which includes the 'node' runtime and the 'npm' package manager; (2) install a code editor like VS Code; (3) create a file ending in .js; (4) run it with the command 'node filename.js' in a terminal. Alternatively, for quick experiments without installing anything, you can open any browser's Developer Tools (F12) and use the Console tab directly.

🏏

Cricket analogy: Setting up is like: (1) join an academy — install Node.js, getting the runtime coach and npm equipment manager together, (2) get your kit (editor), (3) prepare a training plan (.js file), (4) run the session with 'node filename.js' — or for a quick net session, just grab a bat in the backyard (browser DevTools, F12, Console tab).

npm (Node Package Manager) comes bundled with Node.js and lets you install reusable packages, for example by running 'npm install <package-name>' inside a project folder that has a package.json file, created via 'npm init'.

🏏

Cricket analogy: npm is the team's equipment supplier bundled with the academy (Node.js) — you set up a squad roster with 'npm init' (creating package.json) then bring in specific gear with 'npm install <package-name>', like ordering a specific brand of bat for the squad.

A common gotcha for beginners: code run in a browser's console has access to browser-only globals like 'window' and 'document', while code run with Node.js does not have these by default and instead has access to Node-only globals like 'process' and 'require'/'module'. Mixing them up (for example, trying to use 'document.getElementById' inside a plain Node.js script) will throw a ReferenceError.

4. Example

javascript
// app.js
const os = require("os");

function describeEnvironment() {
  return `Node.js is running on platform: ${process.platform}`;
}

console.log(describeEnvironment());
console.log("CPU cores available:", os.cpus().length > 0);

5. Output

text
Node.js is running on platform: linux
CPU cores available: true

6. Key Takeaways

  • Any modern browser's Developer Console can run JavaScript instantly, with no installation required.
  • Node.js is a runtime that executes JavaScript outside the browser, typically via the terminal.
  • Installing Node.js also installs npm, the standard package manager for JavaScript libraries.
  • Run scripts with 'node filename.js'; check tooling with 'node --version' and 'npm --version'.
  • Browser scripts and Node.js scripts have different global objects (window/document vs. process/require).
  • A code editor like VS Code, with syntax highlighting and debugging support, greatly improves productivity.

Practice what you learned

Was this page helpful?

Topics covered

#JavaScript#JavaScriptProgrammingStudyNotes#Programming#SettingUpAJavaScriptEnvironment#Setting#Environment#Syntax#Explanation#StudyNotes#SkillVeris