Nodejs Assignment
Guidelines:
i. This assignment is mandatory for everyone
o deadline extension in
ii. There will only be a single attempt for each exam and n
case of assignments
iii. Any case of unfair means or plagiarism would lead to debarring in final
placements without any further consideration.
iv. Do not use any framework like [Link]/[Link] for building the API endpoints in
this assignment
v. The assignment solutions should be uploaded on Github and links to Github
repositories should be shared with the coach for code review. Make sure to add
appropriate comments in code wherever possible.
Problem 1:
Build an API to calculate current age of user from date of birth
Request URL:- [Link]
Request Method:- GET
Response HTML:-
>Hello John</p>
<p
<p >You are currently 22 years old</p>
Objective:-
Build an API with the above parameters using [Link].
Learnings:
How to make an http-server and endpoints using core [Link] modules.
Problem 2:
Return a JSON response by reading a local file using [Link]
Request URL:- [Link]
Request Method:- GET
Response JSON:-
{
result": {
"
"rootVegetables": [
"turnips",
"ginger",
"beets"
],
"leafyVegetables": [
"broccoli",
"spinach",
"cabbage"
]
}
}
Objective:-
1. Create a file with `.json` extension in your project folder with below data:-
{
"result": {
"rootVegetables": [
"turnips",
"ginger",
"beets"
],
"leafyVegetables": [
"broccoli",
"spinach",
"cabbage"
]
}
}
2. Next read that JSON file in your server route using [Link] file system module. More
details can be found here:-
[Link]
3. Return the data read from the JSON file in your route’s response.
Learnings
How to use [Link] file system module
Problem 3:
Build a area and volume calculation API for various objects based on query params
sent with the request
API URL:- [Link]
Query params types possible:-
object: circle, sphere
metric: 1. area(For circle)
2. volume or surfaceArea(For Sphere)
radius: Integer value
Objective:-
Build an API which can calculate area of a circle or volume/surface area of a sphere
based on inputs sent via query params.
For example:-
If the URL is `[Link]
Then you need to calculate volume of a sphere with radius 5 units as shown below:-
Refer to the query params section stated in the problem to understand other
possible combinations.
Learnings
How to use functions with request routes in [Link]