Skip to content

Commit 47409e9

Browse files
committed
Add Node.js backend project guidelines and test file guidelines,
also added a script command for runSoloWorker
1 parent 1dd217d commit 47409e9

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# Node.js Backend Project Guidelines
3+
---
4+
5+
### Project Setup
6+
- Use **Node.js (v18+)** and **Express.js** for building APIs.
7+
- Store configuration in environment variables (`.env`), and use the config files already present, if they exist.
8+
- follow ES6+ JavaScript conventions.
9+
10+
### Style & Formatting
11+
- Use **camelCase** for variables and function names.
12+
- Apply **2-space indentation**.
13+
- Prefer **single quotes** for strings.
14+
- Always use **async/await** for asynchronous operations.
15+
- Use **ESLint** with the **Airbnb Base** style guide (see `.eslintrc` or `package.json`).
16+
17+
18+
### Architecture & Patterns
19+
- Organize code into clear layers: `routes/`, `controllers/`, `services/`, `models/`.
20+
- Keep business logic in services; route handlers should be thin.
21+
22+
### Error Handling & Security
23+
- Implement centralized error handling middleware (must include status codes and JSON error messages), or adhere to existing code that handles it
24+
- Always validate and sanitize inputs.
25+
- For cookies or sessions, ensure `httpOnly`, `secure` (in prod), and `sameSite: 'strict'`.
26+
27+
### Testing
28+
- Use **Mocha** for unit tests, always look for /tests/*/*.js or /test/*.js to learn the styling and test formats
29+
- Maintain ≥80% test coverage.
30+
31+
### Build & Deployment
32+
- Build command: `npm run build`.
33+
- Start server with `npm start`;
34+
35+
### Documentation & Maintenance
36+
- Tag PRs with [FEATURE], [BUGFIX], or [REFACTOR].
37+
38+
---
39+
40+
```markdown
41+
---
42+
applyTo: "tests/**/*.js"
43+
---
44+
45+
# Test File Guidelines
46+
- Write clear, descriptive test names.
47+
- Use `describe` and `it` blocks from Jest.
48+
- Clean up any test data or mocks after each test.

core/worker/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test:cov": "NODE_ENV=test ./node_modules/nyc/bin/nyc.js --reporter=html --reporter=text --reporter=lcov mocha test --timeout=10000 --colors --recursive --exit",
1111
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
1212
"start": "node app",
13-
"build": "dockerfile/build.sh worker"
13+
"build": "dockerfile/build.sh worker",
14+
"runSoloWorker": "./runSoloWorker.sh green-alg 4444"
1415
},
1516
"repository": {
1617
"type": "git",

0 commit comments

Comments
 (0)