wt (2)
wt (2)
wt (2)
url binding" could refer to the process of binding or associating a route URL with
a specific handler function. This process allows you to define how your
application responds to various HTTP requests sent to specific URLs.
1.Defining Routes: You use Express's methods like app.get(), app.post(), etc., to
define what happens when certain URLs are accessed with specific HTTP
methods.
const express = require('express');
const app = express();
app.get('/hello', function(req, res) {
res.send('Hello, World!');});
app.post('/submit', function(req, res) {
res.send('Form submitted successfully!');});
app.listen(3000, function() {
console.log('Server is listening on port 3000');});
-Accessing http://localhost:3000/hello will respond with "Hello, World!".
-Sending a POST request to http://localhost:3000/submit will respond with "Form
submitted successfully!".
2.Dynamic Parts of URLs: You can also have dynamic parts in URLs, like
/users/:id, where :id represents a variable. Express will then capture whatever
value is there and make it available in req.params.
app.get('/users/:id', function(req, res) {
const userId = req.params.id;
res.send(`User ID: ${userId}`);});
-Accessing http://localhost:3000/users/123 will respond with "User ID: 123".
Data Modelling
1.Understand app needs: Know what data types, relationships, and usage
patterns are required.
2.Identify entities: Pinpoint objects and their relationships, like one-to-one or
many-to-many.
3.Embed or reference: Choose between embedding related data or referencingit.
4.Denormalization: Duplicate data across documents to optimize reads,
balancing with update concerns.
5.Schema design: Define document structure for consistency and performance
benefits.
6.Indexing: Create indexes on frequently queried fields to speed up reads.
7.Data access patterns: Design the model to align with common queries for
optimal performance.
8.Sharding and scaling: Plan for data distribution across servers or clusters for
scalability.
9.Performance and storage: Analyze data volume and growth to ensure efficient
storage and retrieval.
10.Data migration and evolution: Anticipate future changes and plan for schema
updates and migrations.