Important
This repository is read-only / archived and will not recieve updates.
configs:
contains all configurations e.g. database login info in db.config.ts
controllers:
houses all controller methods which get requests from routes and convert them into HTTP responses using middleware and services as needed
middlewares:
contains all middleware (software that lets software communicate with other software) in one place e.g. authentication
routes:
single file for each logical set of routes e.g. routes for one type of resource, can be further broken down e.g. by versions of API
models:
contains data models for database
services:
contains all the business logic e.g. services to represent objects and methods to run queries on the database
- mkdir and cd
- npm init -y
- npm install express && npm install mongoose && npm install typescript
- touch app.ts and added that code
- npm i serverless-http
- sudo npm install -g serverless
- serverless --version to check install
- export AWS_ACCESS_KEY_ID= then can test using printenv
- export AWS_SECRET_ACCESS_KEY= (Note: to remove env vars just do exec bash)
- touch serverless.yml and add that code
- serverless deploy (do this last)
- npm install mongodb express cors dotenv
- mkdir routes and touch record.ts and added that code
- tsc app.ts and record.ts
- add Jest as dependency: npm i --save-dev @types/jest
%%{init: {'theme': 'neutral', 'themeVariables': { 'fontSize': '32px', 'fontFamily': 'arial'}}}%%
flowchart TD
Client["Client\n(Browser)"] ---> |HTTP Request| app[app.ts]
app --> books{Does the path \nbegin with /books?}
books --> |Yes| route[books.route.ts]
route --> booksCreate{Does the path \nbegin with /books/create?}
route --> booksSearch{Does the path \nbegin with /books/search?}
booksCreate --> |Yes| controlCreate[booksController.create]
booksSearch --> |Yes| controlSearch[booksController.search]
controlCreate --> |req.body.book| bookCreate[book.create]
controlSearch --> |req.query.description| bookSearch[book.search]
bookCreate --> |book| dbbUpload[dbb.upload]
bookSearch --> |description| dbbQuery[dbb.query]
dbbUpload --> |BookModel.create| mongoose[db.mongoose]
dbbQuery --> |BookModel.find| mongoose
mongoose --> db[MongoDB]