Intro to Node.js & Runtime
Start your backend journey! Learn what Node.js is, how it works, and why it changed web development forever.
Start your backend journey! Learn what Node.js is, how it works, and why it changed web development forever. This hands-on tutorial focuses on practical implementation of intro to node.js & runtime concepts.
Intro to Node.js & Runtime
Welcome to the Backend! π
For a long time, JavaScript only lived in the browser. It handled clicks and animations. If you wanted to build a server (to save data, handle logins), you had to learn PHP, Python, or Java.
Node.js changed everything. It took JavaScript out of the browser and let it run on your computer (server).
1. What is Node.js? π’
What is it? Node.js is NOT a language. It is a JavaScript Runtime Environment. It allows you to execute JavaScript code on a server, outside of a browser.
How it works: It uses Chrome's powerful V8 JavaScript Engine (the same one used in Google Chrome) to compile JS code into machine code that your computer understands.
2. Browser vs. Node.js π
They both speak JavaScript, but they have different "superpowers" (APIs).
| Feature | Browser JS | Node.js |
| :--- | :--- | :--- |
| DOM Access | β
Yes (document, window) | β No (No HTML/CSS) |
| File System | β No (Security risk) | β
Yes (Read/Write files) |
| Global Object | window | global |
| Modules | ES Modules (import) | CommonJS (require) & ES Modules |
3. Running Your First Node Script πββοΈ
You don't need an HTML file anymore. You run JS files directly using the terminal.
- Create a file named
app.js. - Write some code.
- Run
node app.jsin your terminal.
4. Node.js Globals π
Since there is no window, Node gives us other global variables.
global: The equivalent ofwindow.__dirname: Path to the current directory.__filename: Path to the current file.process: Info about the current Node.js process.
5. Non-Blocking I/O (The Secret Sauce) β‘
Node.js is famous for being Non-Blocking and Asynchronous.
Imagine a waiter in a restaurant:
- Blocking (PHP/Java/Python classic): Waiter takes an order, waits for the chef to cook it, serves it, and ONLY THEN takes the next order. (Slow!)
- Non-Blocking (Node.js): Waiter takes an order, gives it to the chef, and IMMEDIATELY takes the next order. When food is ready, the chef rings a bell (Callback). (Fast!)
AI Mentor
Confused about "Node.js runtime, V8 engine, non-blocking I/O, and global objects"? Ask our AI mentor for a simplified explanation.
Quiz
Quiz
Question 1 of 4What is Node.js?
Key Takeaways
β
Node.js runs JS on the server.
β
Uses Chrome V8 Engine.
β
No DOM (window is gone, global is here).
β
Non-Blocking architecture makes it fast for I/O.
What's Next?
Node.js has a massive ecosystem of libraries. Let's learn how to install them using NPM (Node Package Manager)!
Keep coding! π