Node.js and basics of backend
What is MVC?
We learnt about the most common MVC pattern in the backend MVC stands for - Model, View and Controller. Model is the data model, or how the data looks. View is how data is represented, controller is how model is linked to view.
Different backend frameworks
We can make backends with different languages -
- JavaScript (Node.js, Express)
- Go (Gin)
- PHP and Laravel
- Python (Django, Flask, FastAPI)
- If someone wants to learn more in the future in backend they can pursue / learn a fullstack framework like Next.js
Monolith server and microarchitectural server
Monolith servers
Monolith servers are servers where all the functionalities required for the application run on the same server and they don’t rely on any external server for any functionality.
Microarchitectural server
Microarchitectural servers have different parts of the server running on different servers.
What is node.js
Node.js is a javascript based runtime which can be used to run js backend. Node.js uses v8 engine used by chrome as the backend to run javascript on bare metal.
To make a node.js based project after installing node.js we need to -
- run
npm init
to intialize the repository. - Edit the scripts in
package.json
- run
npm run start
to run the project. - If you are commiting node.js based project, never commit node modules in github.
Making a base node.js based server
node.js
const express = require("express")
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.json({message: "Hello from CSE 3rd year"})
})
app.post("/", (req, res) => {
res.json({message: req.body})
})
app.listen(4000, () => {
console.log("server listening on port 4000")
})
package.json
{
"name": "day_10",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"express": "^4.21.0"
},
"devDependencies": {
"nodemon": "^3.1.7"
}
}