generated from knackroot-technolabs-llp/rest-api-using-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 20a3567
Showing
78 changed files
with
17,831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.vscode | ||
**/node_modules/ | ||
/dist | ||
logs/ | ||
.git | ||
*.md | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SECRET=xyz #helpul when you add authentication with your API but currently we are not using decodeToken Middleware | ||
PORT=8000 | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD= | ||
REDIS_USERNAME=default | ||
REDIS_HOST=127.0.0.1 | ||
DATABASE_URI=mongodb://127.0.0.1:27017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
dist/* | ||
build/* | ||
**/*.d.ts | ||
/src/types/ | ||
node_modules | ||
**/**/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"extends": ["plugin:@typescript-eslint/recommended"], | ||
"parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: NodeJS with Webpack | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x, 18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Build | ||
run: | | ||
npm install | ||
npx webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
.env | ||
dist | ||
sample.txt | ||
logs | ||
log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx --no-install commitlint --edit $1 | ||
yarn commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint:fix && yarn format && npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
node_modules | ||
build | ||
.yarn | ||
.husky | ||
**/**/node_modules | ||
*.lock | ||
*.log | ||
.gitignore | ||
.npmignore | ||
.prettierignore | ||
.DS_Store | ||
.eslintignore | ||
.npmrc | ||
.nvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"bracketSpacing": true, | ||
"printWidth": 80, | ||
"proseWrap": "preserve", | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"useTabs": true, | ||
"parser": "typescript", | ||
"arrowParens": "always", | ||
"requirePragma": true, | ||
"insertPragma": true, | ||
"endOfLine": "lf", | ||
"overrides": [ | ||
{ | ||
"files": "*.json", | ||
"options": { | ||
"singleQuote": false | ||
} | ||
}, | ||
{ | ||
"files": ".*rc", | ||
"options": { | ||
"singleQuote": false, | ||
"parser": "json" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"editor.suggest.snippetsPreventQuickSuggestions": false, | ||
"aiXcoder.showTrayIcon": true, | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": ["source.fixAll.format", "source.fixAll.eslint"], | ||
"editor.tabSize": 2, | ||
"cSpell.words": ["Parens", "plusplus"] | ||
} |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.4.1.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM ubuntu | ||
|
||
|
||
RUN apt-get update | ||
RUN apt-get install -y curl | ||
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - | ||
RUN apt-get upgrade -y | ||
RUN apt-get install -y nodejs | ||
|
||
COPY package.json package.json | ||
COPY package-lock.json package-lock.json | ||
COPY src src | ||
COPY tsconfig.json tsconfig.json | ||
COPY .env .env | ||
|
||
COPY nodemon.json nodemon.json | ||
|
||
RUN npm install -g ts-node nodemon | ||
RUN npm install ts-node --save-dev | ||
RUN npm install typescript -g | ||
RUN npm install typescript --save-dev | ||
ENV PORT 8000 | ||
ENV SECRET 123 | ||
ENV ADMIN_EMAIL [email protected] | ||
|
||
EXPOSE 8000:8000 | ||
|
||
CMD ["nodemon", "src/server.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Ultimate Backend API Starter Kit | ||
### A robust and production-ready backend API starter kit built with TypeScript, Express.js,Zod and Mongoose. | ||
|
||
## Features | ||
- Type-safe API development with TypeScript,Zod for schema validation. | ||
- Caching Layer using Redis. | ||
- Seamless data modeling and interaction with MongoDB using Mongoose. | ||
- TypeSafe Environment configuration. | ||
- Auth using JWT Strategy or passport. | ||
- Helmet middleware for Strong security headers. | ||
- Cors middleware for Cross-Origin Resource Sharing. | ||
- Rate limiting middleware for enhanced security using express-rate-limit with redis for centralized storage. | ||
- Streamlined error handling and logging using custom httpResponse ,Global Error Handler and httpError. | ||
- Logging (With Colorful Terminal) with winston for better debugging and monitoring. | ||
- Linting,Husky,eslint,prettier,commitlint for code quality. | ||
- Server Health Monitoring using Custom API endpoint. | ||
- Github Actions for CI/CD. | ||
- Docker support for containerized deployment | ||
- MVC Architecture. | ||
- WebSocket Support using ws package (optional). | ||
|
||
|
||
## Prerequisites | ||
|
||
- Node.js (version 18 or higher) | ||
- yarn | ||
- Redis | ||
- MongoDB | ||
|
||
## Installation | ||
|
||
1. Clone the repository: | ||
``` | ||
git clone https://github.com/arunkumar201/rest-api-using-ts.git | ||
``` | ||
2. Navigate to the project directory: | ||
``` | ||
cd rest-api-using-ts | ||
``` | ||
3. Install dependencies: | ||
``` | ||
yarn install | ||
``` | ||
|
||
## Configuration | ||
- Create a `.env` file in the root of the project according to `.env.example` and add the following environment variables: | ||
|
||
## Running the Application | ||
|
||
To start the server in development mode: | ||
``` | ||
yarn dev | ||
``` | ||
For production: | ||
|
||
``` | ||
yarn build | ||
yarn start:prod | ||
``` | ||
## Contributing | ||
- Fork the repository | ||
- Create a new branch | ||
- Make your changes | ||
- Create a pull request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
ignores: [message => message.includes('WIP')], | ||
rules: { | ||
'header-max-length': [0, 'always', 200], // [!code focus] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3' | ||
services: | ||
rest-api-ts: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- mongo | ||
|
||
mongo: | ||
image: mongo:latest | ||
ports: | ||
- "27017:27017" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"module": "commonjs", | ||
"lib": [ | ||
"DOM", | ||
"ES2015" | ||
], | ||
"baseUrl": ".", | ||
"outDir": "./build", | ||
"rootDir": ".", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"allowSyntheticDefaultImports": true, | ||
"pretty": true, | ||
"resolveJsonModule": true, | ||
"plugins": [ | ||
{ | ||
"transform": "typescript-transform-paths" | ||
}, | ||
{ | ||
"transform": "typescript-transform-paths", | ||
"afterDeclarations": true | ||
} | ||
], | ||
"paths": { | ||
"@auth/*": [ | ||
"src/features/auth/*" | ||
], | ||
"@user/*": [ | ||
"src/features/user/*" | ||
], | ||
"@global/*": [ | ||
"src/shared/globals/*" | ||
], | ||
"@service/*": [ | ||
"src/shared/services/*" | ||
], | ||
"@socket/*": [ | ||
"src/shared/sockets/*" | ||
], | ||
"@worker/*": [ | ||
"src/shared/workers/*" | ||
], | ||
"@root/*": [ | ||
"src/*" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"watch":["src"], | ||
"ext":".ts,.js", | ||
"exec":"ts-node ./src/index.ts" | ||
} |
Oops, something went wrong.