https://github.com/albinojunior/node-crudapi-ts
CRUD boilerplate for create Node Restful API's with Express Framework and Sequelize ORM written in Typescript.
https://github.com/albinojunior/node-crudapi-ts
api api-rest boilerplate es6 es7 express expressjs node nodejs nosql orm restful-api sequelize sql typescript
Last synced: 4 months ago
JSON representation
CRUD boilerplate for create Node Restful API's with Express Framework and Sequelize ORM written in Typescript.
- Host: GitHub
- URL: https://github.com/albinojunior/node-crudapi-ts
- Owner: albinojunior
- Created: 2019-02-21T20:22:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T11:07:57.000Z (over 2 years ago)
- Last Synced: 2023-10-20T16:20:55.220Z (over 1 year ago)
- Topics: api, api-rest, boilerplate, es6, es7, express, expressjs, node, nodejs, nosql, orm, restful-api, sequelize, sql, typescript
- Language: TypeScript
- Homepage:
- Size: 330 KB
- Stars: 44
- Watchers: 3
- Forks: 16
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Node CrudAPI Boilerplate | TypeScript
Node boilerplate for create CRUDs and restful API's with Express Framework and Sequelize ORM written in Typescript.
- [1. Installing](#1-installing)
- [Install dependencies](#install-dependencies)
- [Installing pm2](#installing-pm2)
- [Environments](#environments)
- [2. Database](#2-database)
- [Install database driver](#install-database-driver)
- [Database Config](#database-config)
- [Migrations and Seeders](#migrations-and-seeders)
- [Creating Migration](#creating-migration)
- [Running Migration](#running-migration)
- [Creating Seed](#creating-seed)
- [Running Seed](#running-seed)
- [3. Schedules](#3-schedules)
- [Installing](#installing)
- [Configuring](#configuring)
- [4. Running](#4-running)
- [5. Building](#5-building)
- [DEV](#dev)
- [PROD](#prod)
- [6. Docs](#6-docs)## 1. Installing
#### Install dependencies
```bash
$ npm i
```#### Installing pm2
```bash
$ npm i -g pm2
```#### Environments
Copy `.env.example` to `.env` and set environments
## 2. Database
#### Install database driver- **PostgresSQL**
```bash
$ npm install --save pg pg-hstore
```- **MySQL**
```bash
$ npm install --save mysql2
```- **MariaDB**
```bash
$ npm install --save mariadb
```- **SQLite**
```bash
$ npm install --save sqlite3
```- **SQL Server**
```bash
$ npm install --save tedious
```#### Database Config
Setting config database connection on config file: `config/database.js`
***if you will not use migrations or seeds this config can be created with ".ts" extension**
[more config details](http://docs.sequelizejs.com/manual/getting-started.html)#### Migrations and Seeders
- For implements migrations or seeds install sequelize-cli module:```bash
$ npm i -g sequelize-cli
```- Create `database/seeders` and/or `database/migrations` folder
*OBS: You can create seeds or migrations folders individually*- Create a `.sequeilizerc` and paste follow code:
```
module.exports = {
"config": "./config/database.js", //database config file reference
"seeders-path": "./database/seeders", //remove if you don't use seeders
"migrations-path": "./database/migrations" //remove if you don't use migrations
};
```#### Creating Migration
```bash
$ sequelize migration:create --name MIGRATION_NAME
```#### Running Migration
```bash
$ sequelize db:migrate
```#### Creating Seed
```bash
$ sequelize seed:create --name SEED_NAME
```#### Running Seed
```bash
$ sequelize db:seed:all
```## 3. Schedules
#### Installing
- For implements Schedules install node-schedule module:```bash
$ npm i node-schedule --save
``````bash
$ npm i @types/node-schedule --save-dev
```#### Configuring
- Create `src/jobs` folder and view [example](https://github.com/albinojunior/nodeapi-typescript/blob/master/examples/job.example.ts) of job file.
- Create `src/schedule.ts` file ande paste follow code or copy from [example](https://github.com/albinojunior/nodeapi-typescript/blob/master/examples/schedule.example.ts)
```javascript
/* src/schedule.ts */
import { resolve } from "path";
import { scheduleJob } from "node-schedule";import * as fs from "fs";
import { Job } from "./common/interfaces/job";const env = process.env.NODE_ENV || "development";
const prefix = env == "development" ? "" : "build/";export default class Schedule {
public jobs: Job[] = [];public constructor() {
this.getJobs();
}public getJobs = (): void => {
const path = resolve(`${prefix}src/jobs`);
let files = fs.readdirSync(path);
this.jobs = files.map((file): Job => require(`./jobs/${file}`).default);
};public startJobs = (): void => {
this.jobs.map(
(job: Job): void => {
if (job.enabled)
scheduleJob(job.date, async (): Promise => await job.execute());
}
);
};
}```
- Import `src/schedule.ts` on app and call **startJobs()** method on *App* constructor## 4. Running
```bash
$ npm run dev
```## 5. Building
#### DEV
```bash
$ npm run build:dev
```#### PROD
```bash
$ npm run build
```## 6. Docs
- [Sequelize](http://docs.sequelizejs.com/)