Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
Dynamic endpoint with express

I'm trying to generate a dynamic URL that will change everytime an endpoint is called So I have this simple function in Node.js to create a dynamic url:

var path = crypto.createHash('md5').update(`${Date.now()}`).digest("hex");

function createNewPath(){
  path = crypto.createHash('md5').update(`${Date.now()}`).digest("hex");
}

and this simple code to receive the request:

app.use('/'+path, function(req,res){
  createNewPath();
  res.send("<h1>Welcome!<h1>");
});

The problem is that app.use does not reload the value in "path" so the initial url asigned stays the same, any ideas?

Been breaking my head and got nothing

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Don't create the route dynamically. Set it up in advance. Check the hash inside it.

Create a route which takes the hash as a param.

Return an error if it doesn't match.

app.get("/:hash", (req, res) => {

    if (req.params.hash === path) {
        return res.send("<h1>Welcome!<h1>");
    }
    return res.sendStatus(404);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!