Assess your understanding of backend development concepts including project setup, RESTful organization, TypeScript use, MongoDB integration, and secure authentication with JWT. Test your knowledge of best practices for scalable and maintainable APIs.
Which combination of commands correctly initializes a REST API project using TypeScript and installs essential dependencies for Node.js, Express, MongoDB, and JWT authentication?
Explanation: The correct command sequence initializes a Node.js project and installs both runtime and development dependencies, including Express, Mongoose, JWT, TypeScript, and their types. The other options lack parts of the command, misuse package managers, or include unrelated client setup steps.
What is the main benefit of configuring the 'rootDir' and 'outDir' fields in the TypeScript 'tsconfig.json' for a backend project?
Explanation: Setting 'rootDir' and 'outDir' allows you to keep your TypeScript code in one folder and the compiled JavaScript in another, improving maintainability. The other choices are unrelated: TypeScript configuration does not optimize runtime speed, set up deployments, or encrypt variables.
Which approach best adheres to RESTful routing principles when structuring user-related API endpoints?
Explanation: RESTful routing separates resources and actions into logical, meaningful routes. The correct option reflects clear separation of user management and authentication. Combining all actions in one endpoint or using only POST methods does not follow RESTful conventions. Using HTTP headers directly to build queries is insecure and not standard.
Why is it recommended to make a database connection inside a dedicated module and initiate the server only after establishing this connection?
Explanation: Connecting to the database before starting the server ensures stability and prevents the application from serving requests when the database is unreachable. Hardcoding credentials is insecure, and the other options do not reflect best practices or capabilities of MongoDB with TypeScript.
What is the primary role of JWT (JSON Web Token) in securing REST API endpoints?
Explanation: JWTs are used for stateless authentication, allowing servers to verify users without keeping session state. Database backups are unrelated, and unique user-specific routes or password storage in tokens are insecure and not the purpose of JWT.