Skip to content

Latest commit

 

History

History
160 lines (120 loc) · 2.9 KB

readme.md

File metadata and controls

160 lines (120 loc) · 2.9 KB

Sample NodeJS REST API 🌈🌞

This Project Built form Sample project that using NodeJs [es6] with Postgres SQL

Project Structure 📂

Project Sources

Control the APIs

src
├───controllers
├───db
│   └───configs
├───helpers
├───middlewares
├───models
└───apis

Project CLI Built-in

Command-line built-in

├───commands
│   ├───cli
│   ├───controllers
│   ├───models
│   ├───routes
│   ├───sql
│   └───stub
├───migrations
│   └───sql
└───src

Clone the project 📂

git clone https://github.com/pphatdev/sample-node-api-migration.git
cd ./apis-with-nodejs-es6

To Start Project ♻️

Config Database ⚙️

make sure your database local is working. copy .env.exmaple to .env than change the env configuration.

If you skip this step you can't start the node service.

# App Enviroment
VERSION="v1"
APP_NAME="REST APIs with NodeJs"
NODE_ENV="development"

# DB Connection
DB_HOST="your host"
DB_NAME="your database name"
DB_PORT="your PORT"
DB_USER="your username"
DB_PWD="your password"
cp .env.example .env
npm install

Database Migration 🚀🛩️

You can create multi table

Signle table 1️⃣🥰

npm run db:create table_name

Multi tables 🔢🥰

npm run db:create table_name1 table_name2

After Creating sql file you have to update the sql to your own table.

cd ./migrations/sql

Migrate table to Database 〽️

npm run db:migrate

Starting Server 〽️

Finally you can start the project.

npm start

and these what you see on terminal! 😎

♻️  Starting with: [development] Mode!

🌞  Web development:
🚀 Localhost: http://localhost:3000
🚀 Local Service: http://127.0.0.1:3000
🚀 Host Service: http://{ipv4}:3000

🌞  API development:
🚀 Localhost: http://localhost:3000/api/v1/
🚀 Local Service: http://127.0.0.1:3000/api/v1/
🚀 Host Service: http://{ipv4}:3000/api/v1/

Usage 🧭⚡

In this project you can create routes, controllers, and models by cli. How to do that please check documentation below.

Create Routes 📂

npm run create:route routename1, routename2

Create Controllers 📂

npm run create:controller controllername1, controllername2

Create Controllers 📂

npm run create:controller controllername1, controllername2

Create Models 😎

npm run create:model modelname1, modelname2

Create Route, Controller, and Model

You can create route, controller, and model by signle command.

npm run create:rcm rcmname

Bug Report

Help me to Improve