This video is a comprehensive course on building APIs using Node.js and Express. It guides viewers through creating a REST API for managing students and teachers, step-by-step, using Node.js, Express, JavaScript, and TypeScript. The course also covers testing the API with Postman and connecting it to a MySQL database using TypeORM.
get, post, put, patch, and delete.mysql2 package and creating database tables using SQL.The video begins by introducing a course on creating REST APIs using Node.js and Express.js. The instructor, Leonardo, explains that the course will cover building a REST API for managing student and teacher data from scratch. He highlights the technologies used: Node.js, Express.js, JavaScript, and TypeScript, along with Postman for API testing and MySQL for the database, utilizing TypeORM as an Object-Relational Mapper (ORM).
The initial portion of the video (up to minute 19) focuses on setting up the development environment. This includes verifying Node.js installation, initializing a new Node.js project using npm init -y, and installing the Express.js framework via npm install express. Leonardo also introduces and installs the CORS (Cross-Origin Resource Sharing) package for security best practices, explaining its role in controlling which domains can access the API.
The video then moves into a basic "Hello, world!" example in Express.js, demonstrating how to create a simple route that responds to GET requests on the root path ("/"). This illustrates the fundamental structure of an Express.js application, showing how to use require to import the Express module, create an application instance, define a route, and use the listen method to start the server. The concepts of middleware and their sequential execution are briefly introduced. Finally, the video starts to lay the groundwork for a more complex project, outlining the planned architecture (MVC pattern) to manage students and teachers, with separate folders for controllers, views (routes), and models (data). The explanation of RESTful verbs (GET, POST, PUT, PATCH, DELETE) and their corresponding operations is also included.
Sí, exactamente. Los métodos que defines en estudiantesRoutes.js (o cualquier archivo de rutas que crees) son llamados mediante app.use en index.js. app.use en index.js toma como argumento el router que has exportado desde tu archivo de rutas. Al usar app.use, estás montando las rutas definidas en ese router en la aplicación Express principal. De esta manera, cuando una petición llega a la aplicación Express y coincide con una ruta definida en estudiantesRoutes.js, el middleware asociado a esa ruta se ejecuta.