Professional Documents
Culture Documents
Nodejs Assignments: Assignment - 1
Nodejs Assignments: Assignment - 1
Assignment - 1
Write code to get data using different methods like process.argv in node command itself, as env
variable, and using the readline to have interactive terminal session
1. function getNameFromCommandLine() {
// Write you code here, name should be taken as args in process.argv
}
2. function getNameFromEnv() {
// Write your code here
}
3. function getNameFromReadLine() {
// Write your code here
}
Instructions
* In the first function, you would receive name as the last command line argument, you need to
return the name from the function
* In this second function, return the env variable name
* In the last function, accept the name from the command line (terminal) using readline in nodejs
Assignment - 2
● Create a file and serve it using simple http server
● Write code to create a simple file containing the dummy html code provided below using
the fs module, serve the file created using the http server
Instructions
● Create a file called index.html in the same folder using the nodejs fs module before
starting the server
● The index.html file should contain <h1>Hello World</h1>
● Serve the index.html file using nodejs http module
● Server should listen on port 3000
Assignment - 3
# Create a simple nodejs app using express
## Create a nodejs server using express, ejs as view engine, and any other dependencies
required
Instructions
* Create an express server with the routes mentioned below
```
GET / - Base Route, return the homepage or the landing page
GET /form - should render a form
POST /user/add - Should add a user and redirect to base route '/'
```
Assignment - 4
Extension to Assignment - 3
Add PUT and DELETE routes in previous assignments
This is an extension on assignment 3, now use a database to store the users, and create routes
to edit and delete a user
Instructions
Create a dataase connection to mongodb on your localhost with the database name as
assignment_4
Create a user schema with name, email (unique), and a boolean field called isPromoted, default
value null
PUT /user/:id - Edit User Route, toggle the isPromoted field value to true / false
DELETE /user/:id - Delete the user with the id
The user list / card in the base route should show two buttons (Promote / Demote, and Delete)
in every user list / card
Add the buttons in the format below
The Promote / Demote button should call the PUT request with the user id for that user and
should change the user isPrmoted field to true (if it was null or false) else false
Show the users with isPromoted value as null in Yellow, isPrmoted true value in Green,
isPromoted false value in Red
Add one more button called Delete on every user list / card and on clicking the Delete button, it
should call the DELETE routee with the user id and the user should get deleted on the backend
Give the edit button and delete button their unique ids in format (edit-) and (delete-) for their
corresponding users
Redirect to the base route after PUT and DELETE route
Assignment - 5
Create a REST API backend service using NodeJs and Express
Create a backend service for a post sharing application like instagram, the user should be able
to add posts, edit and delete them as required
Instructions