What is Node.js β The Concept of a Runtime
After Completing This Topic
You will be able to answer the question, "What is a runtime?" and install Node.js to run JavaScript files directly in your terminal.
What is a Runtime?
JavaScript was originally designed to run only within web browsers. To create servers, read files, or connect to databases, separate languages like Python or Java were required.
A runtime refers to the environment that enables a specific language to be executed.
- Browser (Chrome, Safari) = The first JavaScript runtime
- Node.js = The second JavaScript runtime (runs directly on your computer)
If you haven't installed Node.js, you won't be able to run .js files in your terminal. The moment you install Node.js, your computer gains the ability to understand and execute JavaScript.
// hello.js β Run in the terminal with `node hello.js`
const message = "Running with Node.js";
console.log(message);
console.log(`Current time: ${new Date().toLocaleTimeString()}`);You can execute this by typing node hello.js in your terminal. No HTML file is needed.
Browser vs. Node.js
Even though it's the same JavaScript, the tasks you can perform depend on the execution environment.
| Browser | Node.js | |
|---|---|---|
| Execution Location | Inside a web page | Your computer's terminal |
| Capabilities | Manipulating the screen, handling button events | Reading files, creating servers, connecting to databases |
| Execution Command | Place <script> in HTML | node filename.js |
Thanks to Node.js, you can now create both the front-end (screen) and back-end (server) using just JavaScript. This is why the term "full-stack" has become a reality in the JavaScript world.
# Check if Node.js is installednode --version# If a version like `v22.x.x` is displayed, it's installed
# Run a JavaScript filenode hello.jsβ Apply to Bio: DevBench β HTML & CSS Basics