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 });