Why
I use this as a bootstrap for quickly getting an API running with PostgreSQL and easier development.
It basically opens a connection pool to PostgreSQL, using pg-promise module.
Has some helper methods for building routes, controllers, and "agents", plus mixing/matching middleware.
To get started, create an index.js file, install pm2 globally, and add a "start" script to your package.json
// package.json"scripts":
// ecosystem.json
// index.jsconst Quickoa = ;const routes = ; const app = ; app;
// routes/index.jsconst Route = ;const findComments addComment } = ; const api = prefix: '/api'; /** Gathers comments for a post with post_id GET /api/posts/:post_id/comments*/api; /** Adds a comment to post with post_id POST /api/posts/:post_id/comments*/api; moduleexportsapi = api;
// controllers/api/comments.jsconst co = ; const CommentAgent = ;const authenticate = ; moduleexportsfindComments = authenticate findCommentsById; moduleexportsaddComment = authenticate addCommentToPost; { }
// agents/comments.jsconst Agent = ;const validator = const serializer = ; const db: postComments } = ; moduleexports = serializer validator repo: postComments;
// serializers/comment.js
const Serializer = require('quickoa/serializer');
const model = require('../models/comment');
const rootKey = 'comment';
module.exports = new Serializer({ rootKey, model });