Skip to content

auxcoder/express-basic-api

Repository files navigation

README

Install

Create a Sqlite DB for development

$ sqlite3 test.db

Install and run

npm install
npm start

Running tests

Currently to make sure that your tests doesn’t listen “twice” from the server.js a check is done

if (!module.parent) {
  app.listen(port);
}

Another options is using Nodemon, as a npm package script:

"test": "nodemon --exec \"mocha --recursive\""

JWT

JSON Web Token Claims


Logs

Logs gets written to file from level debug and up in the all-logs.log files under /logs dir. Errors get logged too into errors.log files. Related logic in /core/logger, using Winston.

TODO:

Refs

Libs & Modules


Project structure

├── config                # App configuration files
│  ├─ serviceOne.json     # ServiceOne config
│  └─ ...                 # Other configurations
├── core                  # Business logic implementation
│  ├─ accounts.js
│  ├─ sales.js
│  ├─ comments.js
│  └─ ...                 # Other business logic implementations
├── logs
│  ├─ all-logs.log        # all logs
│  └─ error-logs.log      # error logs
├── prisma                # Prisma ORM
│  ├─ migrations
│  │  ├─ migration_<name>   # Migrations
│  │  └─ migrations_lock.toml # sqlite DB
│  ├─ accounts.js
│  └─ dev.db              # sqlite DB
├── db                    # Data access stuff
│  └─ prisma.js           # DB instantiation
├── routes
│  ├─ controllers         # Request managers
│  ├─ middleware         # Request middleware
│  └─ routes.js           # Define routes here
├── types              # External services implementation
│  ├─ ...
│  └─ common.js                 # Other services
├─ utils                  # Util libs (formats, validation, etc)
├─ tests                  # Testing
├─ scripts                # Standalone scripts for dev uses
├─ pm2.js                 # pm2 init
├─ package.json
├─ README.md
└─ app.js                 # App starting point

HTTP status codes

http-errors

  • 200  OK, The request was successful
  • 201  CREATED, A new resource object was successfully created
  • 404  NOT FOUND, The requested resource could not be found
  • 400 BAD REQUEST, The request was malformed or invalid
  • 500  INTERNAL SERVER ERROR, Unknown server error has occurred