npx @chatpta/api-starter-express my-api
system has
node 16.4 or higher
docker 3.6.0 or higher
create my-api/.env
file and paste the content of my-api/dev.env
into this file.
Docker runs on localhost:5400
and express api runs on localhost:3000
docker-compose up db-api-starter-express
npm install
npm run migrateDb
npm run devstart
Express runs at localhost:3000
and postgres runs at localhost:5400
docker-compose -f docker-compose.yaml up
Test connection to db need psql
client installed on machine
psql "postgresql://user:password@localhost:5400/chatpta_db"
Run application
npm install
npm run devstart
Run test in watch mode with postgres db connection
npm run test
Run test in watch mode WITHOUT postgres db connection
npm run testWithoutDb
Run the build script to do all of above
./build
Run database migration to create database tables
npm run migrateDb
Seed database with some data
npm run seedDb
Check test coverage
npm run testCoverage
Contains express entry point script www, this script runs in response to npm run start
and npm run devstart
Application wide middleware, like error handlers and loggers.
Configuration file, which does not change frequently. Should not include password or database names etc..
Name is self-explanatory. Controller files should not define functions, but should only call functions. Definition of
functions should be in the controller/lib
directory.
All database connection and related files. In the main application should be used only in ActiveRecord.js
module.
Other places it can be used is in migration and seed scripts.
Factory creates the objects and supplies to the modules dependent on them.
Interfaces on which other modules are dependent for sending messages to each other.
Library of application functions.
Application log files, one file each day.
All models.
All routes.
All secret keys.
All application tests. Each test file correspond to a file of same name. For example user.test.js
tests user.js
file.