Skip to content

Instantly share code, notes, and snippets.

@gusmcnair
Last active August 3, 2021 23:00
Show Gist options
  • Save gusmcnair/be9bf5dbe13d8ef8141210fa8c45fd9a to your computer and use it in GitHub Desktop.
Save gusmcnair/be9bf5dbe13d8ef8141210fa8c45fd9a to your computer and use it in GitHub Desktop.
node test questions
Describe the HTTP requests/response lifecycle.
The client sends the server a request, and the server sends a response, which can be either the requested data or an error.
Describe the architecture of a basic Express app. How is it organized?
An express app has methods for routing HTTP requests (figuring out which route should be used based on request), configuring middleware
(a series of functions often to validate request or determine specifics before sending response), and more.
Organization: Request, middleware, main task, response.
Tell me about a time when you've used Express Router. How was it helpful?
For my Thingful project, is was helpful in that it allowed several different methods (post, delete, get) to be easily configured on
the same route, and some middleware which applied to all of them could be inserted above them using '.all'.
What’s the difference between a unit and an integration test?
Unit testing is for individual components or methods, integration testing tests how they interact or communicate.
What is SQL and how does it relate to PostgreSQL?
SQL is the language of relational databases. PostgreSQL is an open-source database relational database system. PSQL allows us to
interact with the Postgresql server, using the command line.
What is an XSS attack and do you know any steps to take to prevent them?
An XSS attack is when malicious JavaScript is inserted into a database using the POST method. The xss tool can be used to 'sanitize'
this data, erasing it or transforming it into HTML.
What are environmental variables and what might you put in them?
An environmental variable is what it sounds like: a variable that changes depending on the environment (dev, production, testing, etc.)
Environmental variables like PORT, NODE_ENV and base url are often set in config.
Query all data: SELECT * FROM /TABLENAME/;
Query for specific column: SELECT * FROM /TABLENAME/ WHERE /COLUMN NAME/ = /"DESIRED VALUE"/;
Query for set number: SELECT * FROM /TABLENAME/ LIMIT /LIMIT NUMBER/;
Query for specific columns: SELECT /(column, column)/ FROM /(TABLENAME)/;
Query for count: SELECT COUNT(*) FROM /TABLENAME/ WHERE /COLUMN NAME/ = /"DESIRED VALUE"/;
Two WHERE queries: use AND || Either or use OR
Add data: INSERT INTO /TABLENAME/ (categories) VALUES ('data values');
Delete: DELETE FROM /TABLENAME/ WHERE id = /ID/
Order: ORDER BY /COLUMNAME/ ASC/DESC
Update: UPDATE /TABLENAME/ SET /UPDATECOLUMN = ('/UPDATEVALUE/') WHERE ID = /THISID/;
Create table: CREATE TABLE /TABLENAME/ (id SERIAL PRIMARY KEY, category TEXT NOT NULL, category /CATEGORY NAME/ /ENUM TYPE/);
Add column: ALTER TABLE /TABLENAME/ ADD COLUMN /COLUMNNAME/
Delete from table: DELETE FROM /TABLENAME WHERE /CONDITIONS/;
Delete table: DROP TABLE /TABLENAME/ CASCADE;
1. calculator.js: module.exports = {add, subtract, multiply, divide}
2. package.json: Add Express
3. app.js: const express = require('express') AND const app = express();
4. const {add, subtract, multiply, divide} = require('./modules/calculator.js');
5. app.use(add); app.use(subtract); app.use(multiply); app.use(divide);
6. module.exports = app;
1. Cut/paste routers and variables to router file
2. Create const toDoRouter = require('./todo/todo-router')
3. app.use('/v1/todos', toDoRouter) for each route
4. Cut/paste service, xss, jsonparser, path to router file
5. Add const express = require('express') above jsonparser or any other references to express
6. In router file: (top) const toDoRouter= express.Router(); (bottom) module.exports = toDoRouter
7. Insert 'toDoRouter' instead of app or whatever at the top of routes
8. After that, but before GET etc., add .route('/ROUTE HERE/').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment