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
The singleton pattern is used in programming languages such as Java and .NET to define a global variable. A single object used across systems remains constant and needs to be defined only once rather than many times. The singleton pattern is used in programming languages such as Java and .NET to define a global variable. A single object used across systems remains constant and needs to be defined only once rather than many times. A singleton is intended to provide only one instance of itself while facilitating a global point of access.
If you were tasked with building a middleware system like Express uses, what approach might you take to construct/operate it?
The app.get() function is Application-level Middleware. the parameters passed to the method are req, res, and next. These are the incoming request, the response being written, and a method to call to pass the call to the next middleware function once the current middleware is finished. In this case, once the response is sent, the function exits. You could also chain other middleware here by calling the next() method.
const express = require('express'); const app = express();
app.get('/', (req, res, next) => { res.send('Welcome Home'); });
app.listen(3000);
Router Middleware
Router is used to manage these incoming requests. It kind of routes your requests to correct handler/code
Dynamic Module Loading
is a mechanism by which a computer program can, at run time, load a library or other binary into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.
Singleton Pattern
is a software design pattern that restricts the instantiation of a class to one single instance.
CRUD REST Method Matches
CRUD stands for Create, Read, Update, and Delete, which are four primitive database operations. At first glance, these operations map well to the HTTP verbs most frequently used in REST POST , GET , PUT ,DELETE
Mock Testing
is an approach to unit testing that lets you make assertions about how the code under test is interacting with other system modules. In mock testing, the dependencies are replaced with objects that simulate the behaviour of the real ones.