Minimart AppServer
Objectives Attempted
- CRUD for product with JSON response
- Input validation with swagger
- Logging with pino
- Database wrapper ODM with mongoose
Ensure Node and npm is installed
-
Install ts-node
npm install -g ts-node
-
Install dependencies
npm install
-
Setup database The app requires mongodb. You may install it locally or run a docker image https://www.mongodb.com/ or https://hub.docker.com/_/mongo
-
Setup environment variables Create a file .env in the root directory and paste these contents (easiest way)
APP_ID=minimart-appserver
PORT=3001
LOG_LEVEL=debug
REQUEST_LIMIT=100kb
SESSION_SECRET=mySecret
MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_DB=minimartDB
#Swagger
SWAGGER_API_SPEC=/spec
You may change the values to suit your preferences
-
Run the appserver in dev mode
npm run dev
-
To run in production mode
npm run compile
npm start
Boilerplate code was generated with generator-express-no-stress-typescript-mongoose https://www.npmjs.com/package/generator-express-no-stress-typescript-mongoose