Skip to content

Commit 430862a

Browse files
authored
Merge pull request #2 from nabadeep25/dev
📖 DOC: Doc updated, create npx starter command
2 parents f88539d + 42f8cba commit 430862a

File tree

3 files changed

+224
-4
lines changed

3 files changed

+224
-4
lines changed

README.md

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
11
# Typescript-Node-Sequelize-Boilerplate
22

3-
- Node (TypeScript)
3+
A boilerplate/starter project for quickly building RESTful APIs using Node.js,Typescript, Express, and Sequelize.
4+
5+
6+
- Node
7+
- Typescript
8+
- Express
49
- MySql
5-
10+
11+
## Table of Contents
12+
13+
- [Typescript-Node-Sequelize-Boilerplate](#typescript-node-sequelize-boilerplate)
14+
- [Table of Contents](#table-of-contents)
15+
- [Quick start](#quick-start)
16+
- [Manual Installation](#manual-installation)
17+
- [Getting started](#getting-started)
18+
- [For development](#for-development)
19+
- [Sample .ENV](#sample-env)
20+
- [Commands](#commands)
21+
- [Project Structure](#project-structure)
22+
- [API Documentation](#api-documentation)
23+
- [API Endpoints](#api-endpoints)
24+
- [Linting](#linting)
25+
- [Inspirations](#inspirations)
26+
27+
28+
29+
## Quick start
30+
31+
create boillerplate with single command
32+
```
33+
npx @nabadeep25/create-ts-node-app myapp
34+
35+
```
36+
37+
38+
39+
## Manual Installation
40+
41+
steps:
42+
43+
Clone the repo:
44+
45+
```
46+
git clone --depth 1 https://github.com/nabadeep25/typescript-node-sequelize-boilerplate.git foldername
47+
48+
cd folder name
49+
npx rimraf ./.git
50+
```
51+
52+
Install the dependencies:
53+
54+
```
55+
npm install
56+
```
57+
58+
Set the environment variables:
59+
60+
```
61+
cp .env.example .env
62+
63+
```
664
## Getting started
765

866
```
@@ -50,3 +108,84 @@ OTP_SECRET=shgdbnbgw
50108

51109

52110

111+
112+
## Commands
113+
114+
115+
```bash
116+
# run in development
117+
npm run watch
118+
119+
# run in production
120+
npm run start
121+
122+
# lint files
123+
npm run lint
124+
125+
# format files
126+
npm run format
127+
128+
```
129+
130+
131+
132+
133+
## Project Structure
134+
135+
```
136+
src\
137+
|--config\ # Environment variables and configuration related things
138+
|--controllers\ # Route controllers
139+
|--helpers\ # Helper function files
140+
|--middlewares\ # Custom express middlewares
141+
|--model\ # Sequelize models
142+
|--routes\ # Routes
143+
|--services\ # Service
144+
|--utils\ # Utility classes and functions
145+
|--validations\ # Request data validation schemas
146+
|--app.ts # Express app
147+
|--server.ts # App entry point
148+
```
149+
150+
## API Documentation
151+
152+
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.
153+
154+
### API Endpoints
155+
156+
List of available routes:
157+
158+
**Auth routes**:\
159+
`POST api/v1/auth/register` - register\
160+
`POST api/v1/auth/login` - login\
161+
`POST api/v1/auth/forgot-password` - send reset password email\
162+
`POST api/v1/auth/reset-password` - reset password\
163+
164+
165+
**User routes**:\
166+
`GET api/v1/user` - get user info\
167+
`PATCH api/v1/user` - update user\
168+
169+
170+
## Linting
171+
172+
Linting is done using [ESLint](https://eslint.org/) and [Prettier](https://prettier.io).
173+
174+
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.
175+
176+
To modify the ESLint configuration, update the `.eslintrc.json` file. To modify the Prettier configuration, update the `.prettierrc.json` file.
177+
178+
To prevent a certain file or directory from being linted, add it to `.eslintignore` and `.prettierignore`.
179+
180+
To maintain a consistent coding style across different IDEs, the project contains `.editorconfig`
181+
182+
183+
184+
## Inspirations
185+
- [hagopj13/node-express-boilerplate](https://github.com/hagopj13/node-express-boilerplate)
186+
- [microsoft/typescript-node-starter](https://github.com/microsoft/TypeScript-Node-Starter)
187+
188+
189+
190+
191+

bin/cli.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
const path = require("path");
4+
const fs = require("fs");
5+
const { execSync } = require("child_process");
6+
7+
async function runCommand(command) {
8+
try {
9+
execSync(`${command}`, { stdio: "inherit" });
10+
} catch (e) {
11+
console.log(`Failed to execute ${command}`, error);
12+
return false;
13+
}
14+
return true;
15+
}
16+
17+
if (process.argv.length < 3) {
18+
console.log("Please specify the target project directory.");
19+
console.log("For example:");
20+
console.log(" npx @nabadeep25/create-ts-node-app my-app");
21+
process.exit(1);
22+
}
23+
24+
const currentPath = process.cwd();
25+
const folderName = process.argv[2];
26+
const appPath = path.join(currentPath, folderName);
27+
const repo =
28+
"https://github.com/nabadeep25/typescript-node-sequelize-boilerplate.git";
29+
30+
try {
31+
fs.mkdirSync(appPath);
32+
} catch (err) {
33+
if (err.code === "EEXIST") {
34+
console.log(
35+
"Folder already exists. Please choose another name for the project."
36+
);
37+
} else {
38+
console.log(err);
39+
}
40+
process.exit(1);
41+
}
42+
43+
async function setup() {
44+
try {
45+
// Clone repo
46+
console.log(`Downloading files from ${repo}`);
47+
let cloned = runCommand(`git clone --depth 1 ${repo} ${folderName}`);
48+
if (!cloned) process.exit(-1);
49+
console.log("Cloned successfully.\n");
50+
51+
process.chdir(appPath);
52+
53+
console.log("Installing dependencies...\n");
54+
runCommand("npm install");
55+
56+
console.log("Dependencies installed successfully.\n");
57+
58+
fs.copyFileSync(
59+
path.join(appPath, ".env.example"),
60+
path.join(appPath, ".env")
61+
);
62+
console.log("Environment files copied.\n");
63+
64+
runCommand("npx rimraf ./.git");
65+
66+
fs.unlinkSync(path.join(appPath, "bin", "cli.js"));
67+
fs.rmdirSync(path.join(appPath, "bin"));
68+
69+
console.log("Installation is now complete!\n");
70+
console.log("To start developing follow :");
71+
console.log(` cd ${folderName}`);
72+
console.log(" npm run watch");
73+
console.log();
74+
console.log("🎉 Happy coding 💻!");
75+
} catch (error) {
76+
console.log(error);
77+
}
78+
}
79+
80+
setup();

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "typescript-node-sequelize-boilerplate",
3-
"version": "0.1.0",
2+
"name": "@nabadeep25/create-ts-node-app",
3+
"version": "0.1.3",
44
"description": "",
55
"author": "Nabadeep Thakuria",
6+
"bin": "bin/cli.js",
67
"homepage": "https://github.com/nabadeep25/typescript-node-sequelize-boilerplate",
78
"license": "MIT",
89
"keywords": ["typescript","node","express","sequelize","mysql","postgres","boilerplate","template","typescript node sequelize boilerplate","typescript node","typescript sequelize boilerplate"],

0 commit comments

Comments
 (0)