Source
What is Node.js
- JavaScript is previously confined to frontend for interactivity
- Node allows us to run JS on the server side on directly on computers
How computers understand code
- Computers only understand machine code
- Assembly language is built on top of machine code
- C++ also abstracts from assembly code, and it is compiled down to machine code
- However, JS is abstracted even more from machine code, but computers cannot directly understand it
JS can be run inside browsers
- Browsers has an engine called V8 engine, written in C++ by Google
- It compiles JS to machine code in runtime
Node is a wrapper for V8 engine
- Written in C++
- Node allows us to run JS through the V8 compiler inside of node to compile to machine code
- Allows us to run JS on a server or computer
- Also adds more functionality for JS
- Read and write files on a computer
- Connect to a database
- Act as as server for content
What is Node.js used for
- Handle requests from the client and sends it to the client
- Can interact with databases
- Alternative to server side languages like Python, Ruby and PHP
Why Node.js
- Share code between frontend and backend since they both use JS
- Has a massive community with huge amount of third-party packages and tools