Skip to content

This project learning about nodejs and express database using nosql [mongodb] for implement dynamic web

Notifications You must be signed in to change notification settings

porameht/nodejs-express-mongodb-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦖 nodejs-express-mongodb-webapp

project preview

Screen Shot 2565-05-11 at 12 08 05

certificate

Screen Shot 2565-05-11 at 12 20 34

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

About

This project learning about nodejs and express database using nosql [mongodb] for implement dynamic web

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published