The coding conventions are elaborated throughout the documentation. It’s imperative to adhere to the prescribed folder structure, naming conventions, and comments. Good code documentation is crucial and non-negotiable. For every endpoint, API documentation must be included to facilitate the creation of OpenAPI documentation. Here are a few other key points:
  • Utilize TypeScript as the Primary Programming Language

TypeScript brings static typing to JavaScript, ensuring more robust and error-free code. Below is a basic example demonstrating a class definition in TypeScript
class Person {
  constructor(private name: string, private age: number) {}

  public sayHello(): void {
    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
  }
}

  • Employ Named Arguments for Methods

Using named arguments makes your code more readable and self-documenting. It also makes your functions more flexible to changes in the order of arguments.
const greet = (args: { firstName: string, lastName: string }) => {
  const {firstName, lastName} = args;
  console.log(`Hello, ${firstName} ${lastName}!`);
}
  • Use npm for Dependency Management

Npm is a powerful tool for managing dependencies and scripts. Ensure all your dependencies are accurately listed in your package.json file.
  • Leverage the GenericCrudService Class for Default CRUD Operations

The GenericCrudService class streamlines the creation of basic CRUD operations for MongoDB documents. Ensure to extend this class when creating services for new schemas.
import { GenericCrudService } from 'path-to-generic-crud-service';
import { User } from './user.model';

class UserService extends GenericCrudService<User> {
  constructor() {
    super(User);
  }
}
  • Adopt the async/await Syntax for Asynchronous Operations

The async/await syntax simplifies asynchronous code, making it easier to read and understand.
const fetchUserData = async (userId: string): Promise<void> => {
  try {
    const response = await fetch(`/api/users/${userId}`);
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error fetching user data:', error);
  }
}
  • Utilize Predefined Methods from the Documentation

Always refer to the documentation for predefined methods that can expedite your development process. Adhering to the provided methodologies ensures consistency across the codebase and facilitates collaborative development efforts.