Skip to content

Commit

Permalink
Merge pull request #1 from AllStackDev1/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
AllStackDev1 authored Aug 6, 2024
2 parents c11dd04 + 852f49e commit f0917f4
Show file tree
Hide file tree
Showing 54 changed files with 1,208 additions and 457 deletions.
14 changes: 0 additions & 14 deletions .env.development

This file was deleted.

14 changes: 0 additions & 14 deletions .env.test

This file was deleted.

25 changes: 21 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,44 @@ on:
pull_request:
branches: [ "main" ]

env:
DB_HOST: ${{ vars.DB_HOST }}
DB_PORT: ${{ vars.DB_PORT }}
DB_NAME: ${{ vars.DB_NAME }}
REDIS_HOST: ${{ vars.REDIS_HOST }}
REDIS_PORT: ${{ vars.REDIS_PORT }}
REDIS_USER: ${{ vars.REDIS_USER }}
DB_USERNAME: ${{ vars.DB_USERNAME }}
HASHING_SALT: ${{ vars.HASHING_SALT }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
JWT_EXPIRES_IN: ${{ vars.JWT_EXPIRES_IN }}
COOKIES_MAX_AGE: ${{ vars.COOKIES_MAX_AGE }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
COOKIES_SECRET_KEY: ${{ secrets.COOKIES_SECRET_KEY }}

jobs:
cache-and-install:
cache-run-test:
environment: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Run lint
run: pnpm lint
- name: Run tests
run: pnpm test

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.env
.env.development
.env.test
build
coverage
react-email-starter
Expand Down
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ This Express server boilerplate is built using the latest version of Node.js and
- **Error Handling**: Custom `AppError` handler and `catchAsync` function for error handling across routes.
- **Rate Limiter**: To control the rate of requests to the server.
- **Express Session**: For managing user sessions.
- **Redis**: Used for caching.
- **Redis**: Used for rate limit store, tempory session store and caching store.
- **@Type-Cacheable**: Decorator for caching data using redis as store.
- **Zod**: Schema validation library.
- **Architecture**: Follows the Model -> Repository -> Service -> Controller approach.
- **Testing**: Unit testing with Jest and integration testing with Mocha.
- **Testing**: Jest and Supertest.

### Setup Instructions

Expand All @@ -43,17 +44,29 @@ This Express server boilerplate is built using the latest version of Node.js and
3. **Set up environment variables**
Create a `.env` file in the root directory and add your environment variables:
```env
NODE_ENV=development
SERVER_PORT=8000
SERVER_HOSTNAME=localhost
DB_PORT=5432
DB_NAME=nodejs-sequelized
DB_HOST=localhost
DB_USERNAME=MrCEO
PORT=
HOSTNAME=
DB_PORT=
DB_NAME=nodejs-
DB_HOST=
DB_USERNAME=
DB_PASSWORD=
REDIS_URL=redis://localhost:6379
SESSION_SECRET=your_session_secret
HASHING_SALT=
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USER=default
REDIS_PASSWORD=
SESSION_SECRET=
JWT_SECRET_KEY=
JWT_EXPIRES_IN=1h
COOKIES_SECRET_KEY=
COOKIES_MAX_AGE=3600000
HASHING_SALT=12
```

4. **Build the project**
Expand Down Expand Up @@ -124,8 +137,9 @@ This Express server boilerplate is built using the latest version of Node.js and
```
├── src/
│ ├── configs/
│ │ ├── env.ts
│ │ └── logger.ts
│ │ ├── env.config.ts
│ │ └── logger.config.ts
│ │ └── redis.config.ts
│ ├── controllers/
│ ├── db
│ │ ├── migrations/
Expand All @@ -150,15 +164,21 @@ This Express server boilerplate is built using the latest version of Node.js and
│ │ └── loggerHandler.ts
│ ├── repositories/
│ ├── services/
│ ├── test/
│ │ └── controllers/
│ │ └── models/
│ │ └── repositories/
│ │ └── services/
│ │ └── test.container.ts/
│ │ └── test.context.ts/
│ │ └── test.model.ts/
│ ├── utils/
│ │ ├── appError.ts
│ │ ├── helper.ts
│ │ └── catchAsync.ts
│ └── validators/
│ └── app.ts
│ └── server.ts
├── test/
│ └── unit/
│ └── integration/
├── .env
├── .gitignore
├── .prettierignore
Expand Down
27 changes: 18 additions & 9 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
TEST_MODEL: 'mock' | 'real';

PORT?: string;
HOSTNAME: string;
HOSTNAME?: string;

DB_HOST: string;
DB_PORT: string;
DB_NAME: string;
DB_USERNAME: string;
DB_PASSWORD: string;
DB_HOST?: string;
DB_PORT?: string;
DB_NAME?: string;
DB_USERNAME?: string;
DB_PASSWORD?: string;

REDIS_URL: string;
REDIS_URL?: string;
REDIS_HOST?: string;
REDIS_PORT?: string;

SESSION_SECRET: string;
SESSION_SECRET?: string;

HASHING_SALT: string;
JWT_SECRET_KEY?: string;
JWT_EXPIRES_IN?: string;

COOKIES_SECRET_KEY?: string;
COOKIES_MAX_AGE?: string;

HASHING_SALT?: string;

// Add other environment variables here
}
Expand Down
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default [
},
rules: {
'@typescript-eslint/no-unused-vars': 'error',
// '@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
},
pluginJs.configs.recommended,
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config: Config = {
coverageProvider: 'v8',
testEnvironment: 'node',
roots: ['<rootDir>'],
testTimeout: 30000,
setupFilesAfterEnv: ['reflect-metadata'],
modulePaths: [compilerOptions.baseUrl],
coverageDirectory: './coverage',
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
"db:create": "pnpm run build && NODE_ENV=development npx sequelize-cli db:create",
"db:migrate:up": "pnpm run build && NODE_ENV=development npx sequelize-cli db:migrate",
"db:migrate:undo": "pnpm run build && NODE_ENV=development npx sequelize-cli db:migrate:undo",
"test": "env NODE_ENV=test jest",
"test:watch": "env NODE_ENV=test jest --runInBand --watch ./src/tests/server.test.ts",
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts"
"test": "NODE_ENV=test TEST_MODEL=real jest --runInBand --detectOpenHandles",
"test:watch": "NODE_ENV=test TEST_MODEL=real jest --runInBand --watch",
"lint": "eslint ./src/**/*"
},
"author": "Chinedu",
"license": "ISC",
"dependencies": {
"@type-cacheable/core": "^14.0.1",
"@type-cacheable/ioredis-adapter": "^15.0.1",
"bcrypt": "^5.1.1",
"connect-redis": "^7.1.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
Expand All @@ -42,21 +45,22 @@
"@eslint/js": "^10.0.0",
"@tsconfig/node16": "^16.1.3",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.7",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^22.0.0",
"@types/safe-regex": "^1.1.6",
"@types/supertest": "^6.0.2",
"@types/validator": "^13.12.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.8.0",
"jest": "^29.7.0",
"nock": "^13.5.4",
"nodemon": "^3.1.4",
"prettier": "3.3.3",
"rimraf": "^6.0.1",
Expand All @@ -66,6 +70,6 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.1"
"typescript-eslint": "^8.0.0"
}
}
Loading

0 comments on commit f0917f4

Please sign in to comment.