Skip to content

Commit

Permalink
🎉 Intialize NodeJS and TS bolierplate
Browse files Browse the repository at this point in the history
  • Loading branch information
harshgoel05 committed Feb 8, 2022
0 parents commit 7a359b3
Show file tree
Hide file tree
Showing 27 changed files with 3,320 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_URI= db uri
PORT= port
57 changes: 57 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: [
'airbnb-base',
'eslint:recommended',
'airbnb',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'import/no-unresolved': 0,
'import/prefer-default-export': 0,
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
'prefer-const': [
'error',
{
destructuring: 'any',
ignoreReadBeforeAssign: false,
},
],
'linebreak-style': 0,
'no-unused-vars': 1,
'no-useless-escape': 0,
radix: ['error', 'as-needed'],
'no-param-reassign': 0,
camelcase: 0,
'import/extensions': 0,
'no-use-before-define': 0,
'consistent-return': 0,

// FIx me
'no-console': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'no-underscore-dangle': 0,
'import/no-extraneous-dependencies': 0,
'prefer-destructuring': 0,
'no-unused-expressions': 0,
'no-return-assign': 0,
'no-await-in-loop': 0,
'no-return-await': 0,
},
};
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Expected Behavior

Please describe the behavior you are expecting

# Current Behavior

What is the current behavior?

# Failure Information

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

# URL to test the bug

URL to test the bug

## Steps to Reproduce

Please provide detailed steps for reproducing the issue.

1. step 1
2. step 2
3. you get it...

## Screenshots

Please include screenshots of the bug

## Error Logs

Please include any relevant log snippets or files here.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---

# Expected Behavior

Please describe the behavior you are expecting

# Current Behavior

What is the current behavior?

# Failure Information

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

# URL to test the bug

URL to test the bug

## Steps to Reproduce

Please provide detailed steps for reproducing the issue.

1. step 1
2. step 2
3. you get it...

## Screenshots

Please include screenshots of the bug

## Error Logs

Please include any relevant log snippets or files here.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''
---
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---

# Is your feature request related to a problem? Please describe

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

# Describe the solution you'd like

A clear and concise description of what you want to happen.

# Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

# Revelant Screenshots

Add any other context or screenshots about the feature request here.

# Additional context

Add any other context or screenshots about the feature request here.
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Description

Please include a summary of the change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix
- [ ] New feature
- [ ] Documentation

# Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings
- [ ] I have formatted the changes
- [ ] I have checked my changes
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.vscode
# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
build
docs
uploads
.env.test


# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
28 changes: 28 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@



# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
build
docs
uploads
.env.test

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"endOfLine": "crlf"
}
13 changes: 13 additions & 0 deletions api/health/health-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Router, Request, Response } from 'express';

const healthController = async (req: Request, res: Response) => {
console.log('Hi');
res.status(200).json({ status: true });
};

export const healthRouter = (): Router => {
const router: Router = Router();
router.get('/', healthController);

return router;
};
Empty file added api/health/health-service.ts
Empty file.
20 changes: 20 additions & 0 deletions api/utils/constants/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const TOO_MANY_REQUESTS_ERROR = {
error: 'Too Many Request, Please try after some time!',
};

export const SERVER_ERROR = { code: 500, message: 'Internal Server error' };

export const UNAUTHORIZED_ERROR = {
code: 401,
message: "Stop! Unautorized access, You can't proceed further",
};

export const BAD_REQUEST = {
code: 400,
message: 'Uh,oh! The request is badly made',
};

export const INVALID_RECAPTCHA_CODE = {
code: 401,
message: 'Invalid recaptcha code',
};
2 changes: 2 additions & 0 deletions api/utils/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './errors';
export * from './response';
25 changes: 25 additions & 0 deletions api/utils/constants/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
interface Response {
status: string;
statusCode: number;
message: string;
}

export const generateResponse = (
statusCode: number,
message: string
): Response => {
return {
status: 'success',
statusCode,
message,
};
};

export const generateErrorMessage = (customError: any): Response => {
const errorResponse = {
status: 'error',
statusCode: customError.code,
message: customError.message,
};
return errorResponse;
};
24 changes: 24 additions & 0 deletions api/utils/databases/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MongoClient } from 'mongodb';

let dbClient: MongoClient;

export async function initDbClient(): Promise<MongoClient> {
try {
dbClient = await MongoClient.connect(process.env.DB_URI || '', {
useNewUrlParser: true,
useUnifiedTopology: true,
ignoreUndefined: true,
});
console.log('Connected to Database');
return dbClient;
} catch (error) {
console.log('Cannot connect to Database', error);
}
}

export async function getDbClient(): Promise<MongoClient> {
if (!dbClient) {
await initDbClient();
}
return dbClient;
}
1 change: 1 addition & 0 deletions api/utils/databases/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './database';
Loading

0 comments on commit 7a359b3

Please sign in to comment.