Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 141 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
# Typescript-Node-Sequelize-Boilerplate

- Node (TypeScript)
A boilerplate/starter project for quickly building RESTful APIs using Node.js,Typescript, Express, and Sequelize.


- Node
- Typescript
- Express
- MySql


## Table of Contents

- [Typescript-Node-Sequelize-Boilerplate](#typescript-node-sequelize-boilerplate)
- [Table of Contents](#table-of-contents)
- [Quick start](#quick-start)
- [Manual Installation](#manual-installation)
- [Getting started](#getting-started)
- [For development](#for-development)
- [Sample .ENV](#sample-env)
- [Commands](#commands)
- [Project Structure](#project-structure)
- [API Documentation](#api-documentation)
- [API Endpoints](#api-endpoints)
- [Linting](#linting)
- [Inspirations](#inspirations)



## Quick start

create boillerplate with single command
```
npx @nabadeep25/create-ts-node-app myapp

```



## Manual Installation

steps:

Clone the repo:

```
git clone --depth 1 https://github.com/nabadeep25/typescript-node-sequelize-boilerplate.git foldername

cd folder name
npx rimraf ./.git
```

Install the dependencies:

```
npm install
```

Set the environment variables:

```
cp .env.example .env

```
## Getting started

```
Expand Down Expand Up @@ -50,3 +108,84 @@ OTP_SECRET=shgdbnbgw




## Commands


```bash
# run in development
npm run watch

# run in production
npm run start

# lint files
npm run lint

# format files
npm run format

```




## Project Structure

```
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers
|--helpers\ # Helper function files
|--middlewares\ # Custom express middlewares
|--model\ # Sequelize models
|--routes\ # Routes
|--services\ # Service
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--app.ts # Express app
|--server.ts # App entry point
```

## API Documentation

To view the list of available APIs and their specifications, run the server and go to `http://localhost:5000/api/v1/docs` in your browser. This documentation page is automatically generated using the [swagger](https://swagger.io/) definitions written as comments in the route files.

### API Endpoints

List of available routes:

**Auth routes**:\
`POST api/v1/auth/register` - register\
`POST api/v1/auth/login` - login\
`POST api/v1/auth/forgot-password` - send reset password email\
`POST api/v1/auth/reset-password` - reset password\


**User routes**:\
`GET api/v1/user` - get user info\
`PATCH api/v1/user` - update user\


## Linting

Linting is done using [ESLint](https://eslint.org/) and [Prettier](https://prettier.io).

In this app, ESLint is configured to follow the [Airbnb JavaScript style guide](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base) with some modifications. It also extends [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to turn off all rules that are unnecessary or might conflict with Prettier.

To modify the ESLint configuration, update the `.eslintrc.json` file. To modify the Prettier configuration, update the `.prettierrc.json` file.

To prevent a certain file or directory from being linted, add it to `.eslintignore` and `.prettierignore`.

To maintain a consistent coding style across different IDEs, the project contains `.editorconfig`



## Inspirations
- [hagopj13/node-express-boilerplate](https://github.com/hagopj13/node-express-boilerplate)
- [microsoft/typescript-node-starter](https://github.com/microsoft/TypeScript-Node-Starter)





80 changes: 80 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path");
const fs = require("fs");
const { execSync } = require("child_process");

async function runCommand(command) {
try {
execSync(`${command}`, { stdio: "inherit" });
} catch (e) {
console.log(`Failed to execute ${command}`, error);
return false;
}
return true;
}

if (process.argv.length < 3) {
console.log("Please specify the target project directory.");
console.log("For example:");
console.log(" npx @nabadeep25/create-ts-node-app my-app");
process.exit(1);
}

const currentPath = process.cwd();
const folderName = process.argv[2];
const appPath = path.join(currentPath, folderName);
const repo =
"https://github.com/nabadeep25/typescript-node-sequelize-boilerplate.git";

try {
fs.mkdirSync(appPath);
} catch (err) {
if (err.code === "EEXIST") {
console.log(
"Folder already exists. Please choose another name for the project."
);
} else {
console.log(err);
}
process.exit(1);
}

async function setup() {
try {
// Clone repo
console.log(`Downloading files from ${repo}`);
let cloned = runCommand(`git clone --depth 1 ${repo} ${folderName}`);
if (!cloned) process.exit(-1);
console.log("Cloned successfully.\n");

process.chdir(appPath);

console.log("Installing dependencies...\n");
runCommand("npm install");

console.log("Dependencies installed successfully.\n");

fs.copyFileSync(
path.join(appPath, ".env.example"),
path.join(appPath, ".env")
);
console.log("Environment files copied.\n");

runCommand("npx rimraf ./.git");

fs.unlinkSync(path.join(appPath, "bin", "cli.js"));
fs.rmdirSync(path.join(appPath, "bin"));

console.log("Installation is now complete!\n");
console.log("To start developing follow :");
console.log(` cd ${folderName}`);
console.log(" npm run watch");
console.log();
console.log("🎉 Happy coding 💻!");
} catch (error) {
console.log(error);
}
}

setup();
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "typescript-node-sequelize-boilerplate",
"version": "0.1.0",
"name": "@nabadeep25/create-ts-node-app",
"version": "0.1.3",
"description": "",
"author": "Nabadeep Thakuria",
"bin": "bin/cli.js",
"homepage": "https://github.com/nabadeep25/typescript-node-sequelize-boilerplate",
"license": "MIT",
"keywords": ["typescript","node","express","sequelize","mysql","postgres","boilerplate","template","typescript node sequelize boilerplate","typescript node","typescript sequelize boilerplate"],
Expand Down