project preview
certificate
π 1. The first page
- setting up express
- running express
- debugging option πΎ
require('chalk') require('morgan') require('debug')
- serving HTML index.js
π2. Setting up Tooling
- npm script πΎ
"start": "node app.js"
- nodemon πΎ
"start": "nodemon app.js"
- nodemon config in package.json πΎ
"nodemonConfig": { "restartable": "rs", "delay": 2500, "env":{ "PORT":4000 }
- nodemon config in package.json πΎ
- environmental variables πΎ
const PORT = process.env.PORT || 3000
π3. Templating Engines
- templating engines
- passing data to a page by ejs
- working with a template HTML CSS
π4. using routing to build multiple pages
- building a web application
- building routes for application
- separating files
- parameter variable πΎ
sessionsRouter.route("/:id").get((req, res) => { const id = req.params.id; res.render("session", { session: sessions[id], });
π5. connecting to a database (nosql)
- setting mongodb πΎ
https://cloud.mongodb.com/ => {name: "nodejs-globomantics"} npm install mongodb const { MongoClient } = require("mongodb");
- using mongodb πΎ
const url = "mongodb+srv://<user>:<password>@nodejs-globomantics.iymsi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"; const dbName = "nodejs-globomantics";
- inserting data πΎ
const response = await db.collection('sessions').insertMany(sessions); res.json(response);
- querying data
- selecting sessions πΎ
const sessions = await db.collection("sessions").find().toArray(); res.render("sessions", { sessions });
- selecting one session πΎ
const session = await db.collection("sessions").findOne({ _id: new ObjectID(id) }); res.render("session", { session });