https://github.com/rkgitvinay/node-express-pg-boilerplate
Production ready starter boilerplate for building RESTful APIs using Node.js, Express, and PostgreSQL
https://github.com/rkgitvinay/node-express-pg-boilerplate
api authentication backend boilerplate express knex nodejs objection objectionjs postgres rest-api starter-template
Last synced: 2 months ago
JSON representation
Production ready starter boilerplate for building RESTful APIs using Node.js, Express, and PostgreSQL
- Host: GitHub
- URL: https://github.com/rkgitvinay/node-express-pg-boilerplate
- Owner: rkgitvinay
- Created: 2025-04-04T13:17:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-04T13:33:11.000Z (about 1 year ago)
- Last Synced: 2025-07-09T15:55:22.015Z (12 months ago)
- Topics: api, authentication, backend, boilerplate, express, knex, nodejs, objection, objectionjs, postgres, rest-api, starter-template
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ RESTful Node.js Express + PostgreSQL API Boilerplate
A modern boilerplate/starter project to kickstart your backend APIs using **Node.js**, **Express.js**, **PostgreSQL**, **Objection.js**, and **Knex.js**.
Built for scalability, security, and productivity. Ideal for RESTful API development with JWT Auth, Swagger Docs, Docker, and a clean project structure.




## Manual Installation
If you would still prefer to do the installation manually, follow these steps:
Clone the repo:
```bash
git clone https://github.com/rkgitvinay/node-express-pg-boilerplate.git
cd
npx rimraf ./.git
```
Install the dependencies:
```bash
npm install
```
Set the environment variables:
```bash
cp .env.example .env
# open .env and modify the environment variables (if needed)
```
## Features
- ๐ **Node + Express** setup
- ๐๏ธ **PostgreSQL** with **Knex.js** & **Objection.js**
- ๐ **JWT-based Authentication** (with Passport.js)
- โ
**Request Validation** using Joi
- ๐ **Swagger API Docs** at `/v1/docs`
- ๐งช **Jest** for Unit & Integration Testing
- ๐ก๏ธ Helmet, CORS, Input Sanitization for **Security**
- ๐ณ **Docker support** for seamless deployment
- ๐ Modular and scalable **Project Structure**
- ๐ฆ Environment management with `.env`
## Commands
Running locally:
```bash
npm run dev
```
Running in production:
```bash
npm run start
```
Testing:
```bash
# run all tests
npm run test
```
## Migration & seed commands:
```bash
# Run all migrations
npm run migrate
# Roll back last migration
npm run migrate:rollback
# Create a new migration
npm run migrate:make migration_name
# Run seed files
npm run seed
# Create a new seed file
npm run seed:make seed_name
```
## Environment Variables
The environment variables can be found and modified in the `.env` file. They come with these default values:
```bash
# Port number
PORT=3000
# JWT
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=30
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30
# Database - PostgreSQL
PG_DB_HOST=localhost
PG_DB_PORT=5432
PG_DB_USER=postgres
PG_DB_PASSWORD=postgres
PG_DB_NAME=node-boilerplate
```
## Project Structure
```
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers (controller layer)
|--docs\ # Swagger files
|--middlewares\ # Custom express middlewares
|--database\ # Database models, migrations, seed
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--index.js # App entry point
|--app.js # Express app
```
## API Documentation
To view the list of available APIs and their specifications, run the server and go to `http://localhost:3000/v1/docs` in your browser. This documentation page is automatically generated using the [swagger](https://swagger.io/) definitions written as comments in the route files.
## Reference
[https://github.com/hagopj13/node-express-boilerplate](https://github.com/hagopj13/node-express-boilerplate)