git clone https://github.com/Global-Software-Consulting/super-express-app.git
cd super-express-app
Install the dependencies:
npm install
Set the environment variables:
cp .env.example .env
# open .env and modify the environment variables
- Features
- Commands
- Environment Variables
- Project Structure
- Stripe Integration
- Authentication
- Validation
- Roles
- Linting
- Heroku
- postgres database: object data modeling using sequelize
- Authentication: using jwt
- Validation: validation of fields enabled using express-validator
- API testing: with postman
- Environment variables: using [dotenv]
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Linting: with ESLint and Prettier
- Editor config: consistent editor configuration
Running locally:
npm run dev
Running in production:
npm start
Migrations:
# run all migrations
npm run db:migrate
# undo migration
npm run db:migrate:undo
Seeders:
# run all seeders
npm run db:seed
# undo seeding
npm run db:seed:undo
Linting:
# run ESLint
npm run lint
Test:
# run tests
npm run test
The environment variables can be found and modified in the .env
file. They come with these default values:
# Port number
PORT=4000
#Database name
DB_NAME=here your db name
#Username
DB_USERNAME=db user name
#Username set for postgres
DB_PASSWORD=database password
#locally you can use 'localhost'
DB_HOST=database host
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_EXPIRES_IN=30
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers
|--middleware\ # Custom express middleware
|--migrations\ # Database migrations
|--models\ # Sequelize models
|--routes\ # Routes
|--seeders\ # Database seeders
|--utils\ # Utility classes and functions
|--validators\ # Validate fields
|--index.js # App entry point
test\
Create subscription Plans by admin
"name":"basic",
"monthlyPrice":5,
"annualPrice":55
User can buy subscription monthly or yearly
"interval": "monthly",
"subscriptionPlanId": selected subscription plan id
Add payment card
"number":payment card number,
"exp_month":expiry month,
"exp_year":expiry year
List of available routes:
Blog routes:
POST /api/v1/blog
- add blog
GET /api/v1/blog
- get all blogs
GET /api/v1/blog/:id
- get a blog
PATCH /api/v1/blog/:id
- update blog
DELETE /api/v1/blog/:id
- delete user
To require authentication for certain routes, you can use the auth
middleware.
const express = require('express');
const auth = require('../middleware/auth');
const { userController } = require('../controller');
const router = express.Router();
router.patch('/:id', auth, userController.update);
using express-validator validate required fields
const express = require('express');
const auth = require('../middleware/auth');
const { userController } = require('../controller');
const { userValidator } = require('../validators');
const router = express.Router();
router.patch(
'/signup',
userValidator.signup(),
userValidator.validate,
auth,
userController.signup
);
Role base tasks
const { blogController } = require('../controllers');
const auth = require('../middleware/auth');
const { checkRole } = require('../middleware/roles');
router.post('/', auth, checkRole('admin', 'editor'), blogController.add);
Linting is done using ESLint and Prettier.
Deployed on heroku here is live heroku link SuperApp