This is a tutorial about building a REST API using Node.js, Express.js, JavaScript, and MySQL database.
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser.
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. It is particularly well-suited for building REST APIs, as it simplifies routing, middleware integration, and HTTP request handling.
MySQL is a popular open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) to manage and organize data. In a REST API, MySQL serves as the persistent data storage layer where application data is stored in tables with defined relationships.
MySQL is well-suited for REST APIs because it:
mysql2A RESTful API is an architectural style for an application programming interface (API) that uses HTTP requests to access and manipulate data. The main HTTP methods used in REST APIs are:
Example REST API Structure:
For a user management system, typical endpoints might look like:
GET /api/users - Get all usersGET /api/users/:id - Get a specific user by IDPOST /api/users - Create a new userPUT /api/users/:id - Update an entire user recordPATCH /api/users/:id - Update specific fields of a userDELETE /api/users/:id - Delete a userA REST API is a backend application. In programming, the terms frontend and backend refer to different parts of a software application, each handling specific responsibilities.
Frontend:
Backend:
In summary, the frontend is responsible for the user experience, while the backend manages behind-the-scenes processes that enable functionality and data interaction.
Full-Stack Development:
A full-stack developer works with both the frontend and backend, bridging the gap between the user interface and server-side operations. Full-stack development involves using a combination of frontend and backend technologies to build complete applications.
In web development, programming languages can be classified as client-side or server-side. This classification refers to where the code is executed: on the client (the user's device) or the server.
Click the buttons to see how PHP and JavaScript work differently.
JavaScript was traditionally a client-side language executed in web browsers. However, with the introduction of Node.js, it can also be executed on the server.