0% found this document useful (0 votes)
2 views

Node.js Backend Assignment (1)

The document outlines a backend assignment to create a Node.js web server using TypeScript and MongoDB, featuring REST endpoints for managing users, posts, and comments. It includes specific API endpoints for loading, deleting, and retrieving user data, as well as guidelines for error handling and data formatting. Submission requires zipping the code and sharing a Google Drive link, while public repositories are prohibited.

Uploaded by

omgudadhe162162
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Node.js Backend Assignment (1)

The document outlines a backend assignment to create a Node.js web server using TypeScript and MongoDB, featuring REST endpoints for managing users, posts, and comments. It includes specific API endpoints for loading, deleting, and retrieving user data, as well as guidelines for error handling and data formatting. Submission requires zipping the code and sharing a Google Drive link, while public repositories are prohibited.

Uploaded by

omgudadhe162162
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Backend Assignment

Task Description
You will design a simple Node.js web server/application, having a set of REST endpoints, and using
MongoDB to store the details.

Dummy data APIs for your use are available at JSON Placeholder (https://jsonplaceholder.typicode.com/).

Quickstarts and References are linked below

1. MongoDB
2. REST API
3. Typescript

● Create a Node.js server using default node packages & typescript


● All request & response bodies should be properly typed
● Create three separate DB collections called users, posts, comments & store the data in the
appropriate DB collection.

Note: Only allowed to use the dependencies mentioned in the below package.json

{
"name": "node_assignment",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^5.0.2"
},
"dependencies": {
"mongodb": "^5.1.0"
}
}

● ts-node can be used to run the server


Rest Endpoints

HTTP verb URL Description

GET /load Loads 10 users into DB, user data should be fetched from
JSON Placeholder along with users' posts, comments &
store the details in appropriate collection, should always
return empty response - with code 200 on success, else
an appropriate error code.

DELETE /users Delete all users in the DB

DELETE /users/:userId Delete user with userId from DB

GET /users/:userId Get the specific user with userId from DB and return user
data including users post & comment for posts in
JSON format. See the user data format below.

PUT /users Put a new user into the DB, and the data is sent to the
server as the request body of this API, which should return
an appropriate error code if the resource already exists;
See the data format below.

Certain details (like the response for some endpoints) are deliberately left empty for you to design
according to best REST practices. Few things for you to think about

● Error code and response if a particular resource doesn't exist when using GET/DELETE
● Error code if POST body has a different userId field that the one it tries to update. Should it even
have a userId in the POST body?
● link header in response of POST/PUT
● Schema for users/posts/comments
Data format
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
},
"posts": [
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae
ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"comments": [
{
"id": 1,
"name": "id labore ex et quam laborum",
"email": "[email protected]",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo
necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "[email protected]",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod
ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
}
]
},
{
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat
blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi
nulla",
"comments": [
{
"id": 3,
"name": "et fugit eligendi deleniti quidem qui sint nihil autem",
"email": "[email protected]",
"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\naccusamus fugiat
dicta\nvoluptatem rerum ut voluptate autem\nvoluptatem repellendus aspernatur dolorem in"
},
{
"id": 4,
"name": "repellat consequatur praesentium vel minus molestias voluptatum",
"email": "[email protected]",
"body": "maiores sed dolores similique labore et inventore et\nquasi temporibus esse sunt id
et\neos voluptatem aliquam\naliquid ratione corporis molestiae mollitia quia et magnam dolor"
}
]
}
]
}

Submission Guidelines

● Please do not upload to any public source code repository like GitHub
● Please zip up your code and upload it to your Google Drive and share its link with us

You might also like