Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to retain special characters in ExpressJS router URL request ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

There are some special characters that might be used for some other thing instead of just showing in the URL. If we want to use the special characters in the URL we need to encode them. The following table shows the encoded value of each special character.

Also we can use a method called as encodeURIComponent(“a+b!c+d”)

Setting up environment and Execution:


  • Step 1: Create HTML file, and paste the below code for UI.


    <!DOCTYPE html>
            <title>Page Title</title>
            <h2>Welcome To GFG</h2>
            <input id="inp" type="text">
            <button onclick="encode()">Go To</button>
            <script src="./app.js"></script>

  • Step 2: Create JS file, and paste the below code.


    let encode = () => {
        let input = document.getElementById('inp');
        let url = input.value;
        url = encodeURIComponent(url);
        window.location.href = `http://localhost:5000/search?key=${url}`;

  • Output: Run index.html File and the output will


  • Step 1: Initialize node.js project

    npm init
  • Step 2: install required modules

    npm install express
  • Step 3: Code in index.js file


    const express = require("express");
    const app = express();
    // Start server on port 5000
    app.listen(5000, () => {
      console.log(`Server is up and running on 5000 ...`);
    app.get("/search", (req, res) => {

  • Step 4: Run server node index.js.


  • User inputting and submitting the value:
  • After getting the value:

My Personal Notes arrow_drop_up
Last Updated : 21 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials