Git Product home page Git Product logo

nodejs-hapi-template's Introduction

Node Hapi Template

An enterprise Hapi template application built using Nodejs showcasing - Testing Strategies, DB seeding & migrations, integration with an ORM, containerization using Docker, REST Apis, a middleware for authorization, redis caching, rate limited endpoints, paginated endpoints, and directory based routing


Expert teams of digital product strategists, developers, and designers.


We’re always looking for people who value their work, so come and join us. We are hiring!

Nodejs Hapi Template


Out of the box support for

  • Dockerization
  • Authorization middleware
  • Redis Cache
  • Rate Limited endpoints
  • Paginated endpoints
  • Swagger UI
  • Support for directory based routing
  • Simplified support for migrations and seeders using sequelize
  • DAO layer for all database interactions
  • Tests using jest

Setup and Configuration.

Pre-requisites

  • node
  • docker
  • docker-compose
  • mysql
  • redis

Installation

  • Install dependencies using npm

    • npm install

Setup

  • Run ./setup-local.sh
  • This will seed the data in mysql and run the server.

Auto Generate models from database

  • Automatically generate bare sequelize models from your database. https://github.com/sequelize/sequelize-auto

Example: sequelize-auto -o "./models" -d temp_dev -h localhost -u root -p 3306 -x password -e mysql

Sequelize

Sequelize is a promise-based ORM for Node.js. It supports the dialects PostgreSQL, MySQL, SQLite and MSSQL and features solid transaction support, relations, read replication and more.

Install Sequelize:

  • npm install -g sequelize-cli

Full documentation: https://sequelize.readthedocs.io/en/latest/

MySQL Setup

Install MySQL

  • brew install mysql

  • This helps in accessing the database(temp_dev)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

To Access mysql

  • mysql -uroot -p

  • This will ask for password and the altered password is password

  • Start Server mysql.server start

  • Stop Server mysql.server stop

redis Setup

Install

  • brew install redis

Start

  • brew services start redis

Stop

  • brew services stop redis

Migrations

With migrations you can transfer your existing database into another state and vice-versa.

Setting up Sequelize Migrations for a initial database

Steps

  1. Create a resources folder
  2. Create individual .sql files for each table and add it sequentially, by prefixing by 01,02 & so on.
  3. Each file should contain the proper sql syntax.
  4. Point the migration files to /resources/v1
  5. Run npx sequlize db:migrate

Structure with example

    /
        migrations/
            20191014145811-initial-migration.js
        resources/
            v1/
                01_create_school.sql
                02_create_student.sql

Database State Changes

  1. Create a migration file that prefixes with the timestamp add it in the /migrations folder. Ex: 20191014145811-alter-student.js
  2. Add the .sql file in the /resources/v2
  3. Point the new migration file to /resources/v2
  4. Run npx sequlize db:migarte --name migartions/20191014145811-alter-student.js

Structure

    /
        migrations/
            20191015143811-initial-migration.js
            20191014145811-alter-student.js
        resources/
            v1/
                01_create_school.sql
                02_create_student.sql
            v2/
                03_alter_student.sql

nodejs-hapi-template's People

Contributors

alichherawalla avatar christin-wednesday avatar sharan-salian avatar rohan-saroha avatar girichetan avatar anurag-wednesday avatar shounak-mulay avatar alihafizji avatar apoorv-mishra avatar debarshib13 avatar vishnu-wednesday 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.