reading-notes
Project maintained by mr-atta
Hosted on GitHub Pages — Theme by mattgraham
Authentication
Explain what a “Singleton” is (in Computer Science terms) ?
- A singleton is a class that allows only a single instance of itself to be created and gives access to that created instance.
- It is used in scenarios when a user wants to restrict instantiation of a class to only one object
Explain how the Singleton pattern can be used with Node modules, specifically with classes ?
- Node.js modules can behave like Singletons, but they are not guaranteed to be always singleton. There are two reasons for this and both are mentioned in the official Node.js documentation:
-
Node’s module caching mechanism is case-sensitive:
-
Modules are cached based on their resolved filename
-
In Node.js, files and modules are in one-to-one correspondence.
-
This object has two methods and an internal private variable called “value”.
If you were tasked with building a middleware system like Express uses, what approach might you take to construct/operate it?
-
Create a new project and npm init it…
npm init
npm install express --save
-
Create server.js with following code:
- Run the server by
node server.js
-
local host: http://localhost:3000 »> should see “Welcome Home” printed in your browser.
- In Express, you can set up middleware to be “global” middleware; meaning it will be called for every incoming request.
app.use((req, res, next) => {
console.log(req);
next();
});
link
link
link
Preparation Materials
Securing Passwords
Basic Auth
OWASP auth cheatsheet
bcrypt docs