Part 06 - Server-Side Development
Part 06 - Server-Side Development
● Event Emitter:
● Allows objects to emit named events.
● Updating Dependencies:
● npm update - Updates all packages to the latest versions specified by the semver range in
package.json.
● Versioning:
● Semantic Versioning (semver): MAJOR.MINOR.PATCH (e.g., ^1.2.3).
● Common Scripts:
● "start": "node app.js" - Starts the application.
● Predefined Scripts:
● prestart, poststart, pretest, posttest - Automatically run before or after a
specific script.
● Popular Libraries:
● Lodash: A utility library for working with arrays, objects, and functions.
● Setting Up Routes
● File: routes/index.js
● Can modify the request and response objects, end the request-response cycle, or call the next
middleware.
● Example: .env
● Authentication Middleware
Example:
● Use plural nouns for collections (e.g., /books for a collection of book resources).
● Sub-Resources:
● Represent resources that belong to a parent resource (e.g., /users/{userId}/orders).
● Token-Based Authentication:
● JWT (JSON Web Tokens): Tokens are signed and can be verified by the server without needing
to store session information.
● OAuth 2.0: Widely used for third-party authentication, involves exchanging tokens between
client and server.
12/26/2024 Dr. Amjad AbuHassan 111
GraphQL: A Query Language for
APIs
● Strongly-typed schema.
posts. email
posts {
title
content
}
}
}
● Long Polling: Server holds the connection open until new information is available.
● Low latency.
● Server responds with a 101 status code, ● send(), onmessage, onopen, onclose
switching the protocol to WebSocket. events.
● Communication Flow:
● Persistent connection remains open.