nodejs-quickstart-structure 1.17.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-quickstart-structure",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "type": "module",
5
5
  "description": "The ultimate nodejs quickstart structure CLI to scaffold Node.js microservices with MVC or Clean Architecture",
6
6
  "main": "bin/index.js",
@@ -12,7 +12,12 @@
12
12
  "test:e2e": "npm run test:e2e:windows",
13
13
  "test:e2e:windows": "node scripts/validate-windows.js",
14
14
  "test:e2e:linux": "node scripts/validate-linux.js",
15
- "test:verify:mongo": "node scripts/verify-migration.js"
15
+ "test:verify:mongo": "node scripts/verify-migration.js",
16
+ "docs:dev": "vitepress dev docs",
17
+ "docs:build": "vitepress build docs",
18
+ "docs:preview": "vitepress preview docs",
19
+ "security:check": "npm audit && npm run snyk:test",
20
+ "snyk:test": "snyk test"
16
21
  },
17
22
  "keywords": [
18
23
  "nodejs",
@@ -45,6 +50,13 @@
45
50
  "fs-extra": "^11.3.0",
46
51
  "inquirer": "^13.3.2"
47
52
  },
53
+ "overrides": {
54
+ "esbuild": "^0.25.0"
55
+ },
56
+ "devDependencies": {
57
+ "snyk": "^1.1303.2",
58
+ "vitepress": "^1.0.0-rc.45"
59
+ },
48
60
  "files": [
49
61
  "bin",
50
62
  "lib",
@@ -12,7 +12,7 @@ const swaggerSpecs = require('./swagger');
12
12
  <%_ } -%>
13
13
  <%_ if (communication === 'GraphQL') { -%>
14
14
  const { ApolloServer } = require('@apollo/server');
15
- const { expressMiddleware } = require('@apollo/server/express4');
15
+ const { expressMiddleware } = require('@as-integrations/express4');
16
16
  const { ApolloServerPluginLandingPageLocalDefault } = require('@apollo/server/plugin/landingPage/default');
17
17
  const { unwrapResolverError } = require('@apollo/server/errors');
18
18
  const { ApiError } = require('../../errors/ApiError');
@@ -1,3 +1,4 @@
1
+ import { env } from '@/config/env';
1
2
  import express from 'express';
2
3
  import cors from 'cors';
3
4
  import helmet from 'helmet';
@@ -15,7 +16,7 @@ import swaggerSpecs from '@/config/swagger';<% } %>
15
16
  <%_ if (communication === 'Kafka') { -%>import { kafkaService } from '@/infrastructure/messaging/kafkaClient';<%_ } -%>
16
17
  <%_ if (communication === 'GraphQL') { -%>
17
18
  import { ApolloServer } from '@apollo/server';
18
- import { expressMiddleware } from '@apollo/server/express4';
19
+ import { expressMiddleware } from '@as-integrations/express4';
19
20
  import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
20
21
  import { unwrapResolverError } from '@apollo/server/errors';
21
22
  import { ApiError } from '@/errors/ApiError';
@@ -23,8 +24,6 @@ import { typeDefs, resolvers } from '@/interfaces/graphql';
23
24
  import { gqlContext, MyContext } from '@/interfaces/graphql/context';
24
25
  <%_ } -%>
25
26
 
26
- import { env } from '@/config/env';
27
-
28
27
  const app = express();
29
28
  const port = env.PORT;
30
29
 
@@ -4,6 +4,10 @@ variables:
4
4
  stages:
5
5
  - lint
6
6
  - test
7
+ <% if (includeSecurity) { %>
8
+ - security
9
+ - quality
10
+ <% } %>
7
11
  - build
8
12
 
9
13
  cache:
@@ -12,19 +16,19 @@ cache:
12
16
 
13
17
  install_dependencies:
14
18
  stage: .pre
15
- image: node:22-alpine
19
+ image: node:22-slim
16
20
  script:
17
21
  - npm ci
18
22
 
19
23
  lint_code:
20
24
  stage: lint
21
- image: node:22-alpine
25
+ image: node:22-slim
22
26
  script:
23
27
  - npm run lint
24
28
 
25
29
  run_unit_tests:
26
30
  stage: test
27
- image: node:22-alpine
31
+ image: node:22-slim
28
32
  script:
29
33
  - npm run test:coverage
30
34
 
@@ -37,7 +41,44 @@ run_e2e_tests:
37
41
  - apk add --no-cache nodejs npm docker-compose
38
42
  - npm ci
39
43
  - npm run test:e2e
44
+ <% if (includeSecurity) { %>
45
+ snyk_scan:
46
+ stage: security
47
+ image: node:22-alpine
48
+ script:
49
+ - npm ci
50
+ - npm run snyk:test
51
+ only:
52
+ - main
40
53
 
54
+ snyk_container_scan:
55
+ stage: security
56
+ image: docker:20.10.16
57
+ services:
58
+ - docker:20.10.16-dind
59
+ script:
60
+ - apk add --no-cache nodejs npm
61
+ - npm install -g snyk
62
+ - docker build -t <%= projectName %>:latest .
63
+ - snyk container test <%= projectName %>:latest --file=Dockerfile --severity-threshold=high --skip-unused-projects
64
+
65
+ sonarqube_check:
66
+ stage: quality
67
+ image:
68
+ name: sonarsource/sonar-scanner-cli:latest
69
+ entrypoint: [""]
70
+ variables:
71
+ SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
72
+ GIT_DEPTH: "0"
73
+ cache:
74
+ key: "${CI_JOB_NAME}"
75
+ paths:
76
+ - .sonar/cache
77
+ script:
78
+ - sonar-scanner
79
+ only:
80
+ - main
81
+ <% } %>
41
82
  build_app:
42
83
  stage: build
43
84
  image: node:22-alpine
@@ -0,0 +1,45 @@
1
+ # Snyk (https://snyk.io) policy file, default is to interrupt on any vulnerability found.
2
+ # This file ignores vulnerabilities internal to the package manager (npm) itself,
3
+ # as they do not affect your application's production security posture.
4
+ version: v1.18.2
5
+ ignore:
6
+ # Minimatch ReDoS/Complexity in npm internal dependencies
7
+ SNYK-JS-MINIMATCH-15353387:
8
+ - '*':
9
+ reason: Internal npm dependency, does not affect application runtime.
10
+ expires: '2027-03-27T10:00:00.000Z'
11
+ SNYK-JS-MINIMATCH-15353389:
12
+ - '*':
13
+ reason: Internal npm dependency, does not affect application runtime.
14
+ expires: '2027-03-27T10:00:00.000Z'
15
+ SNYK-JS-MINIMATCH-15309438:
16
+ - '*':
17
+ reason: Internal npm dependency, does not affect application runtime.
18
+ expires: '2027-03-27T10:00:00.000Z'
19
+ # Tar Symlink Attack in npm internal dependencies
20
+ SNYK-JS-TAR-15456201:
21
+ - '*':
22
+ reason: Internal npm dependency, does not affect application runtime.
23
+ expires: '2027-03-27T10:00:00.000Z'
24
+ SNYK-JS-TAR-15416075:
25
+ - '*':
26
+ reason: Internal npm dependency, does not affect application runtime.
27
+ expires: '2027-03-27T10:00:00.000Z'
28
+ SNYK-JS-TAR-15307072:
29
+ - '*':
30
+ reason: Internal npm dependency, does not affect application runtime.
31
+ expires: '2027-03-27T10:00:00.000Z'
32
+ # Brace-expansion Infinite Loop in npm internal dependencies
33
+ SNYK-JS-BRACEEXPANSION-15789759:
34
+ - '*':
35
+ reason: Internal npm dependency, does not affect application runtime.
36
+ expires: '2027-03-27T10:00:00.000Z'
37
+ SNYK-JS-ISAACSBRACEEXPANSION-15208653:
38
+ - '*':
39
+ reason: Internal npm dependency, does not affect application runtime.
40
+ expires: '2027-03-27T10:00:00.000Z'
41
+ # Picomatch ReDoS in npm internal dependencies
42
+ SNYK-JS-PICOMATCH-15765511:
43
+ - '*':
44
+ reason: Internal npm dependency, does not affect application runtime.
45
+ expires: '2027-03-27T10:00:00.000Z'
@@ -3,9 +3,16 @@
3
3
  # ==========================================
4
4
  FROM node:22-alpine AS builder
5
5
 
6
+ # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
7
+ RUN apk update && apk upgrade && \
8
+ apk add --no-cache ca-certificates zlib>=1.3.2-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
9
+
6
10
  WORKDIR /app
7
11
  ENV NPM_CONFIG_UPDATE_NOTIFIER=false
8
12
 
13
+ # Upgrade npm using corepack (safer in Alpine)
14
+ RUN corepack enable && corepack prepare npm@11.6.4 --activate
15
+
9
16
  COPY package*.json ./
10
17
  COPY tsconfig*.json ./
11
18
 
@@ -22,16 +29,26 @@ COPY . .
22
29
  # ==========================================
23
30
  FROM node:22-alpine AS production
24
31
 
32
+ # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
33
+ RUN apk update && apk upgrade && \
34
+ apk add --no-cache ca-certificates zlib>=1.3.2-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
35
+
25
36
  WORKDIR /app
26
37
 
27
38
  ENV NODE_ENV=production
28
39
  ENV NPM_CONFIG_UPDATE_NOTIFIER=false
29
40
 
41
+ # Upgrade npm using corepack (safer in Alpine)
42
+ RUN corepack enable && corepack prepare npm@11.6.4 --activate
43
+
30
44
  COPY package*.json ./
31
45
 
32
46
  # Install ONLY production dependencies
33
47
  RUN npm ci --only=production --ignore-scripts --no-audit --no-fund || npm ci --only=production --ignore-scripts --no-audit --no-fund || npm ci --only=production --ignore-scripts --no-audit --no-fund
34
48
 
49
+ # Remove npm and caches to achieve Zero-Vulnerability status in the final image
50
+ RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx /root/.npm /root/.cache
51
+
35
52
  # Copy built artifacts from builder
36
53
  <% if (language === 'TypeScript') { %>
37
54
  COPY --from=builder /app/dist ./dist
@@ -52,4 +69,5 @@ RUN mkdir -p logs && chown -R node:node logs
52
69
 
53
70
  USER node
54
71
 
55
- CMD ["npm", "start"]
72
+ # Start application directly with node (safe even without npm)
73
+ CMD ["node", "<% if (language === 'TypeScript') { %>dist/index.js<% } else { %>src/index.js<% } %>"]
@@ -31,29 +31,34 @@ pipeline {
31
31
  }
32
32
  }
33
33
 
34
- // stage('Build') {
35
- // steps {
36
- // sh 'npm run build'
37
- // }
38
- // }
39
-
40
- // stage('SonarQube Analysis') {
41
- // environment {
42
- // scannerHome = tool 'SonarScanner'
43
- // }
44
- // steps {
45
- // withSonarQubeEnv('SonarQube') {
46
- // sh "${scannerHome}/bin/sonar-scanner"
47
- // }
48
- // }
49
- // }
34
+ <% if (includeSecurity) { %>
35
+ stage('SonarQube Analysis') {
36
+ environment {
37
+ scannerHome = tool 'SonarScanner'
38
+ }
39
+ steps {
40
+ withSonarQubeEnv('SonarQube') {
41
+ sh "${scannerHome}/bin/sonar-scanner"
42
+ }
43
+ }
44
+ }
50
45
 
51
- // stage('Security Scan') {
52
- // steps {
53
- // sh 'npm audit --audit-level=high'
54
- // }
55
- // }
46
+ stage('Security Scan') {
47
+ steps {
48
+ sh 'npm audit --audit-level=high'
49
+ sh 'npm run snyk:test'
50
+ }
51
+ }
56
52
 
53
+ stage('Snyk Container Scan') {
54
+ steps {
55
+ script {
56
+ sh 'docker build -t <%= projectName %>:latest .'
57
+ sh 'snyk container test <%= projectName %>:latest --file=Dockerfile --severity-threshold=high --skip-unused-projects'
58
+ }
59
+ }
60
+ }
61
+ <% } %>
57
62
  // stage('Docker Build & Push') {
58
63
  // steps {
59
64
  // script {
@@ -3,85 +3,92 @@
3
3
  ![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)
4
4
  ![License](https://img.shields.io/badge/License-ISC-blue.svg)
5
5
  <% if (language === 'TypeScript') { %>![TypeScript](https://img.shields.io/badge/Language-TypeScript-blue.svg)<% } else { %>![JavaScript](https://img.shields.io/badge/Language-JavaScript-yellow.svg)<% } %>
6
+ <% if (includeSecurity) { %>
7
+ [![Snyk Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/yourusername/<%= projectName %>?style=flat-square)](https://snyk.io/)
8
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=<%= projectName %>&metric=alert_status)](https://sonarcloud.io/)
9
+ <% } %>
6
10
 
7
- A production-ready Node.js microservice generated with **<%= architecture %>** and **<%= database %>**.
8
- This project comes pre-configured with industry-standard tooling for **Code Quality**, **Testing**, and **Security**.
11
+ A production-ready Node.js microservice generated with **<%= architecture %>** and **<%= database %>**.
12
+ This project follows a strict **7-Step Production-Ready Process** to ensure quality and scalability from day one.
13
+
14
+ ---
15
+
16
+ ## 🚀 7-Step Production-Ready Process
17
+
18
+ 1. **Initialize Git**: `git init` (Required for Husky hooks and security gates).
19
+ 2. **Install Dependencies**: `npm install`.
20
+ 3. **Configure Environment**: Copy `.env.example` to `.env`.
21
+ 4. **Start Infrastructure**: `docker-compose up -d<% if (database !== 'None') { %> db<% } %><% if (caching === 'Redis') { %> redis<% } %><% if (communication === 'Kafka') { %> kafka<% } %>`.
22
+ 5. **Run Development**: `npm run dev`.
23
+ 6. **Verify Standards**: `npm run lint` and `npm test` (Enforce 80% coverage).
24
+ 7. **Build & Deploy**: `npm run build` followed by `npm run deploy` (via PM2).
25
+
26
+ ---
9
27
 
10
28
  ## 🚀 Key Features
11
29
 
12
30
  - **Architecture**: <%= architecture %> (<% if (architecture === 'Clean Architecture') { %>Domain, UseCases, Infrastructure<% } else { %>MVC Pattern<% } %>).
13
- - **Database**: <%= database %> <% if (database !== 'MongoDB') { %>with **Flyway** migrations<% } else { %>with **Mongoose** schemas<% } %>.
14
- - **Security**: Helmet, CORS, Rate Limiting, HPP.
15
- - **Quality**: Eslint, Prettier, Husky, Lint-Staged.
16
- - **Testing**: Jest (Unit & Integration).
17
- - **DevOps**: Multi-stage Docker build, CI/CD ready.
18
-
19
- ## 🔄 CI/CD Pipeline
20
- <%_ if (ciProvider === 'GitHub Actions') { -%>
21
- ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/yourusername/<%= projectName %>/ci.yml?branch=main)
22
- This project includes a **GitHub Actions** workflow located in `.github/workflows/ci.yml`.
23
- It automatically runs:
24
- - Linting
25
- - Tests
26
- - Builds
27
- <%_ } else if (ciProvider === 'GitLab CI') { -%>
28
- ![GitLab CI Status](https://img.shields.io/gitlab/pipeline/yourusername/<%= projectName %>?branch=main)
29
- This project includes a **GitLab CI** configuration in `.gitlab-ci.yml`.
30
- It automatically runs:
31
- - Linting
32
- - Tests
33
- - Builds
34
- <% } else if (ciProvider === 'Jenkins') { -%>
35
- This project includes a **Jenkinsfile** for comprehensive CI/CD.
36
- Pipeline stages:
37
- - Install Dependencies
38
- - Lint
39
- - Test
31
+ - **Database**: <%= database %> <% if (database !== 'None') { %>(via <%= database === 'MongoDB' ? 'Mongoose' : 'Sequelize' %>)<% } %>.
32
+ - **Security**: Helmet, CORS, Rate Limiting, HPP, Snyk SCA.
33
+ - **Quality**: 80%+ Test Coverage, Eslint, Prettier, Husky.
34
+ - **DevOps**: Multi-stage Docker, CI/CD ready (GitHub/GitLab/Jenkins).
35
+ <% if (includeSecurity) { %>- **Enterprise Hardening**: SonarCloud SAST, Security Policies.<% } %>
36
+
37
+ ## 📂 Project Structure
38
+
39
+ The project follows **<%= architecture %>** principles.
40
+ <% if (architecture === 'Clean Architecture') { -%>
41
+ - **Domain**: Pure business logic (Entities/Interfaces).
42
+ - **Use Case**: Application-specific business rules.
43
+ - **Infrastructure**: External concerns (DB, Messaging, Caching).
40
44
  <% } else { -%>
41
- CI/CD is not currently configured, but the project is ready for integration.
45
+ - **Model**: Database schemas and data logic.
46
+ - **View**: Template engines or API responders.
47
+ - **Controller**: Orchestrates flow between Model and View.
42
48
  <% } -%>
43
49
 
44
- ## 🛠️ Getting Started
50
+ ---
51
+
52
+ ## 🛠️ Detailed Getting Started
53
+
54
+ Follow the **🚀 7-Step Production-Ready Process** summary at the top, or follow these detailed instructions:
45
55
 
46
56
  ### 1. Prerequisites
47
57
  - Node.js (v18+)
48
58
  - Docker & Docker Compose
49
59
 
50
- ### 2. Quick Start
60
+ ### 2. Environment Setup
61
+ Copy the example environment file and adjust the values as needed:
51
62
  ```bash
52
- # Initialize Git (Required for Husky)
63
+ cp .env.example .env
64
+ ```
65
+
66
+ ### 3. Infrastructure & App Launch
67
+ ```bash
68
+ # Initialize Git for security hooks
53
69
  git init
54
70
 
55
71
  # Install dependencies
56
72
  npm install
57
73
 
58
- # Setup Git Hooks (Husky)
59
- npm run prepare
60
-
61
- # Start Infrastructure (DB, etc.)
62
- docker-compose up -d
74
+ # Start required services
75
+ docker-compose up -d<% if (database !== 'None') { %> db<% } %><% if (caching === 'Redis') { %> redis<% } %><% if (communication === 'Kafka') { %> kafka<% } %>
63
76
 
64
- # Run Development Server
77
+ # Run the app in development mode
65
78
  npm run dev
66
79
  ```
67
80
 
68
- ### 3. Development Standards
69
- Ensure your code meets quality standards before committing:
70
-
81
+ ### 4. Quality & Standards
71
82
  ```bash
72
- # Run Linter
83
+ # Lint & Format
73
84
  npm run lint
85
+ npm run format
74
86
 
75
- # Run Tests
87
+ # Run Unit/Integration Tests
76
88
  npm test
77
-
78
- # Format Code
79
- npm run format
89
+ npm run test:coverage
80
90
  ```
81
91
 
82
- ## 📂 Project Structure
83
-
84
- The project follows **<%= architecture %>** principles.
85
92
  <% if (communication === 'Kafka') { -%>
86
93
  Microservices communication handled via **Kafka**.
87
94
  <% } else if (communication === 'GraphQL') { -%>
@@ -138,6 +145,13 @@ This project demonstrates a production-ready Kafka flow:
138
145
  [Kafka] Consumer: Received USER_CREATED.
139
146
  [Kafka] Consumer: 📧 Sending welcome email to 'kafka@example.com'... Done!
140
147
  ```
148
+
149
+ ### 🛠️ Kafka Troubleshooting
150
+ If the connection or events are failing:
151
+ 1. **Check Docker**: Ensure Kafka container is running (`docker ps`).
152
+ 2. **Verify Broker**: `KAFKA_BROKER` in `.env` must match your host/port (standard: 9093).
153
+ 3. **Advertised Listeners**: If using Windows/WSL, check `docker-compose.yml` advertisers are correct.
154
+ 4. **Logs**: Check `docker compose logs -f kafka` for start-up errors.
141
155
  <% } -%>
142
156
 
143
157
  <% if (caching === 'Redis') { -%>
@@ -205,7 +219,6 @@ docker build -t <%= projectName %> .
205
219
  docker run -p 3000:3000 <%= projectName %>
206
220
  ```
207
221
  <% } -%>
208
-
209
222
  ## 🚀 PM2 Deployment (VPS/EC2)
210
223
  This project is pre-configured for direct deployment to a VPS/EC2 instance using **PM2** (via `ecosystem.config.js`).
211
224
  1. Install dependencies
@@ -241,8 +254,13 @@ docker-compose down
241
254
  - **CORS**: Configured for cross-origin requests.
242
255
  - **Rate Limiting**: Protects against DDoS / Brute-force.
243
256
  - **HPP**: Prevents HTTP Parameter Pollution attacks.
244
-
245
-
257
+ <% if (includeSecurity) { %>
258
+ ### 🛡️ Enterprise Hardening (Big Tech Standard)
259
+ - **Snyk SCA**: Run `npm run snyk:test` for dependency scanning.
260
+ - **SonarCloud**: Automated SAST on every Push/PR.
261
+ - **Digital Guardians**: Recommended Gitleaks integration for secret protection.
262
+ - **Security Policy**: Standard `SECURITY.md` for vulnerability reporting.
263
+ <% } %>
246
264
  ## 🤖 AI-Native Development
247
265
 
248
266
  This project is "AI-Ready" out of the box. We have pre-configured industry-leading AI context files to bridge the gap between "Generated Code" and "AI-Assisted Development."
@@ -250,4 +268,4 @@ This project is "AI-Ready" out of the box. We have pre-configured industry-leadi
250
268
  - **Magic Defaults**: We've automatically tailored your AI context to focus on **<%= projectName %>** and its specific architectural stack (<%= architecture %>, <%= database %>, etc.).
251
269
  - **Use Cursor?** We've configured **`.cursorrules`** at the root. It enforces project standards (80% coverage, MVC/Clean) directly within the editor.
252
270
  - *Pro-tip*: You can customize the `Project Goal` placeholder in `.cursorrules` to help the AI understand your specific business logic!
253
- - **Use ChatGPT/Gemini/Claude?** Check the **`prompts/`** directory. It contains highly-specialized Agent Skill templates. You can copy-paste these into any LLM to give it a "Senior Developer" understanding of your codebase immediately.
271
+ - **Use ChatGPT/Gemini/Claude?** Check the **`prompts/`** directory. It contains highly-specialized Agent Skill templates. You can copy-paste these into any LLM to give it a "Senior Developer" understanding of your codebase immediately.
@@ -0,0 +1,20 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Only the latest `main` branch is supported for security updates.
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.0.x | :white_check_mark: |
10
+ | < 1.0 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ We take the security of this project seriously. If you believe you have found a security vulnerability, please report it following these steps:
15
+
16
+ 1. **Do not open a public issue.**
17
+ 2. Send an email to the project maintainers (see `package.json`).
18
+ 3. Provide a detailed description of the vulnerability, including steps to reproduce.
19
+
20
+ We will acknowledge your report within 48 hours and work on a fix as soon as possible.
@@ -14,17 +14,13 @@ jobs:
14
14
 
15
15
  runs-on: ubuntu-latest
16
16
 
17
- strategy:
18
- matrix:
19
- node-version: [20.x, 22.x]
20
-
21
17
  steps:
22
18
  - uses: actions/checkout@v4
23
19
 
24
- - name: Use Node.js ${{ matrix.node-version }}
20
+ - name: Use Node.js 22.x
25
21
  uses: actions/setup-node@v4
26
22
  with:
27
- node-version: ${{ matrix.node-version }}
23
+ node-version: 22.x
28
24
  cache: 'npm'
29
25
 
30
26
  - name: Install Dependencies
@@ -41,3 +37,10 @@ jobs:
41
37
 
42
38
  - name: Build
43
39
  run: npm run build --if-present
40
+ <% if (includeSecurity) { %>
41
+ - name: SonarQube Scan
42
+ uses: SonarSource/sonarqube-scan-action@master
43
+ env:
44
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45
+ SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
46
+ <% } %>
@@ -0,0 +1,36 @@
1
+ name: Enterprise Security Scan
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+ schedule:
9
+ - cron: '0 0 * * 1' # Weekly scan
10
+
11
+ jobs:
12
+ node-security:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Run Snyk to check for vulnerabilities
18
+ uses: snyk/actions/node@master
19
+ env:
20
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
21
+ with:
22
+ args: --severity-threshold=high
23
+
24
+ container-security:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Build Docker image
29
+ run: docker build -t <%= projectName %>:latest .
30
+ - name: Run Snyk to check Docker image for vulnerabilities
31
+ uses: snyk/actions/docker@master
32
+ env:
33
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
34
+ with:
35
+ image: <%= projectName %>:latest
36
+ args: --file=Dockerfile --severity-threshold=high --skip-unused-projects
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -99,7 +99,7 @@ services:
99
99
  - mongodb_data:/data/db
100
100
 
101
101
  mongo-migrate:
102
- image: node:22-alpine
102
+ image: node:22-slim
103
103
  working_dir: /app
104
104
  volumes:
105
105
  - .:/app
@@ -1,8 +1,9 @@
1
1
  const { Kafka } = require('kafkajs');
2
+ const { env } = require('./env');
2
3
 
3
4
  const kafka = new Kafka({
4
5
  clientId: 'nodejs-service',
5
- brokers: [process.env.KAFKA_BROKER || 'localhost:9092']
6
+ brokers: [env.KAFKA_BROKER]
6
7
  });
7
8
 
8
9
  module.exports = { kafka };
@@ -9,6 +9,12 @@ jest.mock('kafkajs', () => {
9
9
  };
10
10
  });
11
11
 
12
+ jest.mock('<% if (architecture === "MVC") { %>@/config/env<% } else { %>@/infrastructure/config/env<% } %>', () => ({
13
+ env: {
14
+ KAFKA_BROKER: 'localhost:9092'
15
+ }
16
+ }));
17
+
12
18
  describe('Kafka Configuration', () => {
13
19
  beforeEach(() => {
14
20
  jest.clearAllMocks();
@@ -9,6 +9,12 @@ jest.mock('kafkajs', () => {
9
9
  };
10
10
  });
11
11
 
12
+ jest.mock('@/config/env', () => ({
13
+ env: {
14
+ KAFKA_BROKER: 'localhost:9092'
15
+ }
16
+ }));
17
+
12
18
  describe('Kafka Configuration', () => {
13
19
  beforeEach(() => {
14
20
  jest.clearAllMocks();
@@ -1,6 +1,7 @@
1
1
  import { Kafka } from 'kafkajs';
2
+ import { env } from '@/config/env';
2
3
 
3
4
  export const kafka = new Kafka({
4
5
  clientId: 'nodejs-service',
5
- brokers: [process.env.KAFKA_BROKER || 'localhost:9092']
6
+ brokers: [env.KAFKA_BROKER]
6
7
  });