VOOZH about

URL: https://www.geeksforgeeks.org/node-js/how-to-send-different-html-files-based-on-query-parameters-in-node-js/

⇱ How to send different HTML files based on query parameters in Node.js ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to send different HTML files based on query parameters in Node.js ?

Last Updated : 22 Apr, 2021

The following approach covers how to send different HTML files based on the query parameters in Node.js

Approach: The task can be easily fulfilled by receiving the query parameters and map different HTML files with the respective parameters.

Step 1: Create your project folder and install the express module using the following command:

npm install express

Step 2: Create a main.js file in the root directory of your project and write down the following code in it.

Step 3: Create id1.html and id2.html files in the root directory of your project as shown below.

Step 4: Run the server using the following command from the root directory of the project:

node main.js

Output:

  • Now open your browser and go to http://localhost:8080/id1, you will see the following output when id1 is passed as a query parameter.
👁 Image
  • Now go to http://localhost:8080/id2, you will see the following output when id2 is passed as a query parameter.

    👁 Image
  • Comment

    Explore