NodeJs Creating Server
1. Simple HTTP Server
Write a Node.js script to create a simple HTTP server that responds with "Hello, World!".
2. Serve JSON Data
Create an HTTP server that responds with JSON data.
3. Serve HTML File
Modify the server to serve an HTML file instead of plain text and if the file was not found
respond as “error in loading”.
4. Serve Different Responses Based on URL
Create an HTTP server that returns different responses for /home and /about URLs and if
the URLs doesn’t found respond as “Page not found”.
5. Handling POST Requests
Write a server that handles a POST request and returns the sent data in the response.
6. Serve JSON Based on Query Parameters
Create an HTTP server that parses URL query parameters and returns them as JSON.
7. Redirect Requests
Write an HTTP server that redirects requests from /old to /new and if request not found
respond as “Page not found”.
NodeJS Creating Server with Routes
1. Simple Route for Home Page
Create a simple HTTP server with a route for the home page (/) and if the request not
found respond as “Page not found”.
2. Route for About Page
Add a route to home page(/) for /about that returns "About Us" and if the request not
found respond as “Page not found”.
3. Route for Contact Page
Add a route to home page(/) for /contact that returns "Contact Us" and if the request not
found respond as “Page not found”.
4. Route with Query String Parameters
Handle query string parameters for /greet?name=John and if the request not found
respond as “Page not found”.
5. Route for Products
Create a /products route that responds with "Product List" and if the request not found
respond as “Page not found”.
6. Route for Services
Add a /services route that responds with "Our Services" and if the request not found
respond as “Page not found”.
7. Handling Unknown Routes
Add a fallback route for unknown paths that returns "404 - Page Not Found".
8. Route for /help Page
Add a /help route that returns "Help Page".
9. Route for /blog
Add a /blog route that returns "Blog Posts".
10. Route for /team
Add a /team route that returns "Meet Our Team".
11. Route with URL Parameters (Path Variables)
Create a /user/:id route that returns the user ID from the URL and if the request not
found respond as “Page not found”.
12. Route for Login Form (GET Request)
Create a /login route that displays a simple login form.
13. Route with Dynamic Page Titles
Create a /page/:title route that returns a page with a dynamic title.
14. Route for /gallery with HTML Response
Create a /gallery route that returns an HTML response showing images.
15. Route for Showing Server Time
Create a /time route that returns the current server time.
16. Route for FAQ Page
Add a /faq route that returns an HTML list of frequently asked questions.
NodeJS Query Parameters
1. Greeting Query Route
Create a /greet route that accepts name as a query parameter and returns "Hello,
[name]!".
2. Sum of Numbers Route
Create a /sum route that accepts two query parameters a and b, and returns the sum.
3. Full Name Query Route
Create a /fullname route that accepts first and last as query parameters and returns
"Full name: [first] [last]".
4. Multiply Query Route
Create a /multiply route that accepts x and y as query parameters and returns the
product.
5. Reverse Query Route
Create a /reverse route that accepts a text query parameter and returns the reversed
string.
6. Convert Celsius to Fahrenheit Route
Create a /convert route that accepts a celsius query parameter and returns the
temperature in Fahrenheit.
7. Basic Calculator Query Route
Create a /calculator route that accepts num1, num2, and operation (add, subtract,
multiply, divide) as query parameters and returns the result of the calculation.
8. Uppercase Text Route
Create a /uppercase route that accepts a text query parameter and returns the
uppercase version of the text.
9. Square Number Query Route
Create a /square route that accepts a number query parameter and returns the square
of that number.
10. Cube Number Query Route
Create a /cube route that accepts a number query parameter and returns the cube of
that number.
11. Area of Circle Query Route
Create a /circle route that accepts a radius query parameter and returns the area of the
circle.
12. Power Query Route
Create a /power route that accepts two query parameters base and exponent, and
returns the result of raising the base to the exponent.
13. Length of String Query Route
Create a /length route that accepts a string query parameter and returns the length of
the string.
14. Convert to Lowercase Route
Create a /tolowercase route that accepts a text query parameter and returns the
lowercase version of the text.
15. Concatenate Strings Query Route
Create a /concat route that accepts two query parameters str1 and str2, and returns
their concatenation.
16. Substring Query Route
Create a /substring route that accepts text, start, and end query parameters and returns
the substring.
17. Modulo Operation Query Route
Create a /modulo route that accepts a and b as query parameters and returns the result
of a % b.
18. Factorial Query Route
Create a /factorial route that accepts a number query parameter and returns the
factorial of that number.