Session - 1
- JS engine
- How node comes into the picture -How Js works outside browser?
- Why use Node JS?
- Npm (what and why)?
- npm init // npm install express
- Package.json( Why and What)?
- version (1.0.0)
- scripts
- Let's create first script
- Create second script with nodemon
- package.json VS package-lock.json // command : npm ci
- What is Server ?
- What is HTTP ? and HTTP Server ??
- Create an HTTP Server
- require to import a module // require()
- createServer() method
- server.listen();
- Calling the server endpoint from Postman for Log Server Date- Time
- The Response Object
- res.end();
- res.write(); //Sending Data with Response
- res.writehead(); //Specifying Headers in Response
- Request Object
- req.url - contains the url of the request
- Activity - Extending APIs
- Activity - Advanced Extending APIs
Session 2
- Whats is express ??
- Using Express to create http server and send data
- create an app instance
- app.listen()
- app.get() //adding route
- res.end() , res.json , res.write(), res.send() , res.senStatus() //response
- express request object
- req.params()
- req.query()
- Filter all curency by min_Value -- use req.queryParam,
- What is controller?
- create controller?
- Need of controllers?
- flow of controllers
- Import/export in Node JS?
- require();
- module.exports {};
- In Express, the routes are served in the first come first server manner. ex user search by gender and age route position changed then its work well.
Session 3
- Express Routes
- what is express router?
- Why use??
- How to Manage API versioning?? //ans: router
- Creating a router
- new Router instance //const router = require("express").Router();
- router.get("/");
- Use the routes
- app.use("/path", xyzroutes); Activity == club currency Routes.
- Activity - Club User Routes
- Validating Routes
- if else if else check to validate
- Validations using Joi
- Creating a Joi Schema
- Create a schema with the functions in the Joi object
- Adding Schema Keys
- Create a validator function
- Using the validator function //currencies
- Environment Variables
- How to use environment variables?
- .env file -> // process.env.ROUTE_PASSWORD
- require('dotenv').config() // npm install dotenv
Session 4
- what is middleware
- Why middleware
- middleware Architecture
- flow of excution middleware //create middleware for verify auth //create middleware for validateSearchQuery
mongoDB Database
- How to Storing Stuff in DB
- SQL vs MongoDB
- Intro to MongoDB
- Data is stored in collections and documents
- Documents in MongoDB
- Format of Data in MongoDB //BSON
-
Using Mongo and storing documents
- Use the database test > use test
- Check to see if it has any collections inside it? > db.getCollectionNames()
- Add a new collection named “blogs” if already doesn’t exist > db.createCollection("blogs")
- Add a new collection named “blogs” if already doesn’t exist > db.createCollection("blogs")
- Add some documents to this collection > db.blogs.insert({publishedAt: null, content: "", author: []})
- List down the documents of the blogs collection > db.blogs.find({}).pretty()
-
Storing Data in MongoDB with NodeJS
- what is Object Data Modeling library ODM ??
- What and Why Mongoose ??
- How to use mongoose ??
- npm i mongoose
- Connecting to DB const DB_URI = "mongodb://127.0.0.1:27017";
- mongoose.connect(
${DB_URI}
) - Set specifying DB
-
Mongoose Schema
- Creating a schema
Mongoose Model
mongoose.model("xyz", xyzSchema);
Session 5
-
Create - Writing to DB
- create a new Blogs instance
- const newBlogDoc = new Blogs({title: "First Blog"});
- router.get("/new", createNewBlog);
- app.use("/blogs", blogRoutes)
- update our schema by passing in options object for keys
- Confirm unique title
- Delete the current blogs collection from the mongodb > db.blogs.drop()
- POST- update title dynamically
- router.post()
- Parsing body from POST request -> in----> index.js --> app.use(express.json());
- Confirming the document in the DB > db test > db.getCollectionNames(); [ ]
- Saving the object in the DB -- by use .save()
2.Reading from the DB
1. create getAllBlogs in controller ->
2. Update the routes to support the GET / route that is
controlled by getAllBlogs
router.get()
3.Delete - Removing documents
1. check and remove from from DB command
> db.blogs.find({}).pretty()
> db.blogs.remove(
{ _id: ObjectId("61c81cca4112d97895e4911b") } );
2. need to be able to do this using a network call
1. router.delete("/:id", deleteBlogWithId);
2. controller -- -------> deleteBlogWithId --------
------> findOneAndDelete({ _id: id });
4.Updating content
- findOneAndUpdate(filter, update, { new: true });
- const filter = { _id: id }; //conditions to find the document
- const update = req.body; //updates to be performed
- router.patch("/:id", updateBlogsWithId);
5.Timestamps in Schema
{ timestamps: true }
//will add createdAt and updatedAt timestamps
Session 6
-
Nested Schema
- const authorSchema = new mongoose.Schema({ });
- { _id: false }
- Fixing the validation for emails
- npm i validator
-
Building Queries in MongoDB
- reate a route and a controller
- searchBlogs()
- A special operator $elemMatch
- $or operator
- RegEx
- findOne() vs findById()
- reate a route and a controller
-
Business Logic Layer - Services
- what is Services?? Why ??? application ?? and flow??
- Now get rid of business logic from controllers Step 1 - Create a new service file Step 2 - Transport logic from controller to service
- Activity - Create New Services //Apply oops encapsulate
- Creating Blog Service Class
- Activity - Use classes to create a new blog
- Note on naming conventions
Top comments (2)
codersGyan
Check the data in DB