1. What is Node.js? Like Browser is one host environment of that Javascript of frontend, Node.js is a host environment for Javascript of backend Chrome's Javascript engines V8 has all been cloned and is now maintained as a standalone project working without a browser and enriched with some extra APIs that is basically Node.js, it allows us to run Javascript outside of the browser Compare to V8, Node.js dropped some APIs(e.g. DOM API), and added some APIs(e.g. Filesystem) 2. A Simple Node.js Code Node.js code are just normal javascript code with extra node api In Node.js runtime environment, there are a few globally function (e.g., require) Between different Node.js module (javascript file), we can transfer object through require and export A simple Node.js Code: const fs = require("fs"); const userName = "Light"; fs.writeFile("./user-data.txt", "Name: " + userName, (error) => { if (error) { console.log(error); return; } ...
Server-side sessions and authentication tokens are both methods used to authenticate users and maintain their state over the internet. However, they differ in how they store and manage this information. Server-Side Sessions In server-side sessions, the user state is stored on the server's memory. When a user logs in, the server creates and stores the session data (such as user account data and role) in its memory. The server then sends a session ID to the user's browser, which is typically stored in a cookie. This session ID is sent back to the server with each subsequent request, allowing the server to recognize and authenticate the user. This method requires the server to keep track of active sessions, which can consume significant memory resources if there are many concurrent users . Authentication Tokens Authentication tokens, on the other hand, encapsulate the user state within the token itself. When a user logs in, the server generates a token that contains user informati...
Comments
Post a Comment