This simple backend application, built with Express.js, demonstrates how to set up a basic server, handle routes, and use middleware like CORS. The app fetches user data based on an ID, illustrating how to work with basic HTTP requests and responses.
- Node.js installed on your machine. If you don't have it, you can download it here.
- Basic knowledge of JavaScript and familiarity with HTTP requests.
- Clone the repository or download the source files.
- Open your terminal and navigate to the project directory.
- Install the dependencies:
npm install express cors
- Start the server by running:
node index.js
- The server will start on
http://localhost:8000.
This route fetches user data based on the id parameter.
-
Request:
GET http://localhost:8000/1
Replace
1with any valid user ID (e.g.,2or3). -
Response: If the user is found, you'll get a JSON response like this:
{ "user": { "id": 1, "name": "John Doe" } }If the user is not found, you'll receive a
404response:{ "message": "User not found" }
If this project is outside of your current skill set, consider joining Dev30. Dev30 is a fantastic program designed to help you learn JavaScript, work with a community of developers, and complete hands-on projects that build a solid foundation for entering the world of software engineering.
Follow along with this video tutorial to get more detailed instructions on setting up and understanding the basics of this project.
Check out Node/Express Advanced