Welcome to the Women Techmakers Bamenda (WTM Bamenda) community's backend coding style guide. This document outlines the coding conventions and best practices to follow when contributing to our backend projects. Consistency in coding style helps maintain code readability and makes collaboration smoother.
- General Guidelines
- JavaScript
- Node.js and Express.js
- Database
- API Design
- Testing
- Naming Conventions
- Version Control
- Dependencies
- Additional Resources
- Write clean, readable, and maintainable code.
- Keep your code DRY (Don't Repeat Yourself) by reusing code when applicable.
- Use meaningful variable and function names.
- Avoid commented-out code in the repository; use version control for historical code.
-
Follow ESLint rules for JavaScript code quality.
-
Use semicolons at the end of statements.
-
Use single quotes for strings unless interpolating variables.
-
Use
const
for variables that do not need reassignment,let
for variables that do. -
Use arrow functions for concise anonymous functions.
// Good const age = 30; const name = 'Alice'; // Avoid var x = 10;
-
Adhere to the Node.js Best Practices guidelines.
-
Organize your code into separate modules and follow the CommonJS module pattern.
-
Use Express.js for RESTful APIs and follow RESTful conventions for routes and HTTP methods.
// Example of a RESTful route app.get('/api/users', (req, res) => { // ... });
- Use an ORM (Object-Relational Mapping) or a database library to interact with the database.
- Document the database schema and update it as needed.
- Follow API design best practices, including versioning, proper HTTP status codes, and clear documentation.
- Document your APIs using tools like Swagger or API Blueprint.
- Include information on request and response payloads, authentication, and endpoints.
- Write unit tests using a testing framework like Jest.
- Aim for a high test coverage to ensure code reliability.
- Use descriptive and meaningful names for variables, functions, and files.
- Follow naming conventions like camelCase or snake_case consistently.
- Use Git for version control.
- Create feature branches for each new feature or bug fix.
- Write meaningful commit messages that summarize the changes.
- Document and keep track of project dependencies in a
package.json
file. - Regularly update dependencies to benefit from security patches and new features.