Giter Site home page Giter Site logo

nodejs-express-js-stater's Introduction

RESTful API using Nodejs, Express with relational database Postgres, MySQL

Installation

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

Table of Contents

Features

  • 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

Commands

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

Environment Variables

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

Project Structure

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\
 

Stripe Integration

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

API Endpoints

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

Authentication

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);

validation

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
);

roles

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

Linting is done using ESLint and Prettier.

Heroku

Deployed on heroku here is live heroku link SuperApp

nodejs-express-js-stater's People

Contributors

waseem-mansha-gondal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.