{"id":32563068,"url":"https://github.com/blevs/node-express-api1","last_synced_at":"2026-07-04T04:05:37.221Z","repository":{"id":44316640,"uuid":"206129746","full_name":"Blevs/node-express-api1","owner":"Blevs","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-11T01:43:48.000Z","size":1511,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-03T18:39:13.408Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-03T17:05:36.000Z","updated_at":"2019-09-04T01:52:47.000Z","dependencies_parsed_at":"2023-02-08T21:45:40.530Z","dependency_job_id":null,"html_url":"https://github.com/Blevs/node-express-api1","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/Blevs/node-express-api1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-express-api1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-express-api1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-express-api1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-express-api1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blevs","download_url":"https://codeload.github.com/Blevs/node-express-api1/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-express-api1/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281549787,"owners_count":26520515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T02:56:23.748Z","updated_at":"2025-10-29T02:56:51.922Z","avatar_url":"https://github.com/Blevs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node API Challenge\n\n## Topics\n\n- Building a RESTful API.\n- Performing CRUD operations.\n- Writing API endpoints.\n\n## Assignment\n\nUse Node.js and Express to build an API that performs CRUD operations on users.\n\n### Download Project Files and Install Dependencies\n\n- **Fork** and **Clone** this repository.\n- **CD into the folder** where you cloned the repository.\n- Type `npm install` to download all dependencies listed inside `package.json`.\n\n### Database access\n\nDatabase access will be done using the `db.js` file included inside the `data` folder. This file publishes the following methods:\n\n- `find()`: calling find returns a promise that resolves to an array of all the users contained in the database.\n- `findById()`: this method expects an `id` as it's only parameter and returns the user corresponding to the `id` provided or an empty array if no user with that `id` is found.\n- `insert()`: calling insert passing it a user object will add it to the database and return an object with the `id` of the inserted user. The object looks like this: `{ id: 123 }`.\n- `update()`: accepts two arguments, the first is the `id` of the user to update and the second is an object with the `changes` to apply. It returns the count of updated records. If the count is 1 it means the record was updated correctly.\n- `remove()`: the remove method accepts an `id` as it's first parameter and upon successfully deleting the user from the database it returns the number of records deleted.\n\nNow that we have a way to add, update, remove and retrieve data from the provided database, it is time to work on the API.\n\n### Start the API and Implement Requirements\n\n- To start the server, type `npm run server` from the root folder (where the _package.json_ file is). The server is configured to restart automatically as you make changes.\n- Add the code necessary to implement the API requirements.\n- **Test the API using _Postman_ as you work through the exercises.**\n\n### User Schema\n\nUsers in the database conform to the following object structure:\n\n```js\n{\n  name: \"Jane Doe\", // String, required\n  bio: \"Not Tarzan's Wife, another Jane\",  // String\n  created_at: Mon Aug 14 2017 12:50:16 GMT-0700 (PDT) // Date, defaults to current date\n  updated_at: Mon Aug 14 2017 12:50:16 GMT-0700 (PDT) // Date, defaults to current date\n}\n```\n\n### Write endpoints to perform the following queries\n\nInside `index.js` add the code necessary to implement the following _endpoints_:\n\n| Method | URL            | Description                                                                                                                       |\n| ------ | -------------- | --------------------------------------------------------------------------------------------------------------------------------- |\n| POST   | /api/users     | Creates a user using the information sent inside the `request body`.                                                              |\n| GET    | /api/users     | Returns an array of all the user objects contained in the database.                                                               |\n| GET    | /api/users/:id | Returns the user object with the specified `id`.                                                                                  |\n| DELETE | /api/users/:id | Removes the user with the specified `id` and returns the deleted user.                                                            |\n| PUT    | /api/users/:id | Updates the user with the specified `id` using data from the `request body`. Returns the modified document, **NOT the original**. |\n\n#### Endpoint Specifications\n\nWhen the client makes a `POST` request to `/api/users`:\n\n- If the request body is missing the `name` or `bio` property:\n\n  - cancel the request.\n  - respond with HTTP status code `400` (Bad Request).\n  - return the following JSON response: `{ errorMessage: \"Please provide name and bio for the user.\" }`.\n\n- If the information about the _user_ is valid:\n\n  - save the new _user_ the the database.\n  - return HTTP status code `201` (Created).\n  - return the newly created _user document_.\n\n- If there's an error while saving the _user_:\n  - cancel the request.\n  - respond with HTTP status code `500` (Server Error).\n  - return the following JSON object: `{ error: \"There was an error while saving the user to the database\" }`.\n\nWhen the client makes a `GET` request to `/api/users`:\n\n- If there's an error in retrieving the _users_ from the database:\n  - cancel the request.\n  - respond with HTTP status code `500`.\n  - return the following JSON object: `{ error: \"The users information could not be retrieved.\" }`.\n\nWhen the client makes a `GET` request to `/api/users/:id`:\n\n- If the _user_ with the specified `id` is not found:\n\n  - return HTTP status code `404` (Not Found).\n  - return the following JSON object: `{ message: \"The user with the specified ID does not exist.\" }`.\n\n- If there's an error in retrieving the _user_ from the database:\n  - cancel the request.\n  - respond with HTTP status code `500`.\n  - return the following JSON object: `{ error: \"The user information could not be retrieved.\" }`.\n\nWhen the client makes a `DELETE` request to `/api/users/:id`:\n\n- If the _user_ with the specified `id` is not found:\n\n  - return HTTP status code `404` (Not Found).\n  - return the following JSON object: `{ message: \"The user with the specified ID does not exist.\" }`.\n\n- If there's an error in removing the _user_ from the database:\n  - cancel the request.\n  - respond with HTTP status code `500`.\n  - return the following JSON object: `{ error: \"The user could not be removed\" }`.\n\nWhen the client makes a `PUT` request to `/api/users/:id`:\n\n- If the _user_ with the specified `id` is not found:\n\n  - return HTTP status code `404` (Not Found).\n  - return the following JSON object: `{ message: \"The user with the specified ID does not exist.\" }`.\n\n- If the request body is missing the `name` or `bio` property:\n\n  - cancel the request.\n  - respond with HTTP status code `400` (Bad Request).\n  - return the following JSON response: `{ errorMessage: \"Please provide name and bio for the user.\" }`.\n\n- If there's an error when updating the _user_:\n\n  - cancel the request.\n  - respond with HTTP status code `500`.\n  - return the following JSON object: `{ error: \"The user information could not be modified.\" }`.\n\n- If the user is found and the new information is valid:\n\n  - update the user document in the database using the new information sent in the `request body`.\n  - return HTTP status code `200` (OK).\n  - return the newly updated _user document_.\n\n## Stretch Problems\n\nTo work on the stretch problems you'll need to enable the `cors` middleware. Follow these steps:\n\n- add the `cors` npm module: `npm i cors`.\n- add `server.use(cors())` after `server.use(express.json())`.\n\nCreate a new React application and connect it to your server:\n\n- the React application can be anywhere, but, for this project create it inside the folder for the solution.\n- connect to the `/api/users` endpoint in the API and show the list of users.\n- add a delete button to each displayed user that will remove it from the server.\n- add forms to add and update data.\n- Style the list of users however you see fit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblevs%2Fnode-express-api1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblevs%2Fnode-express-api1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblevs%2Fnode-express-api1/lists"}