Untitled
unknown
javascript
2 years ago
1.0 kB
7
Indexable
// Your task is to create a RESTful API using Node.js and Express.js that allows a user to fetch user data based on their ID. // You are given two arrays of data: const users = [ { id: 1, name: "John Doe", age: 25, }, { id: 2, name: "Jane Smith", age: 30, }, { id: 3, name: "Bob Johnson", age: 35, }, ]; const userData = [ { id: 1, data: { email: "john.doe@example.com", phone: "123-456-7890", }, }, { id: 2, data: { email: "jane.smith@example.com", phone: "234-567-8901", }, }, { id: 3, data: { email: "bob.johnson@example.com", phone: "345-678-9012", }, }, ]; // You are required to implement the following endpoints: // GET /users - Returns a list of all users with their ID, name, and age. // GET /users/:id - Returns the user's ID, name, age, email, and phone number based on the provided id. If the user with the specified id does not exist, return a 404 error with an appropriate message.
Editor is loading...