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

106
Views
How to update content in dynamic URLs in Express?

Below have I created 3 URL's from the fn array. In real life, this would be approx 200 different filenames.

After I have created them, would I like to be able to update the content of the URL's to be either 1 or 0.

With the below PoC, the content doesn't change.

Question

Does anyone know how I can change the content of the URL's on-the-fly?

const express = require('express');
const app = express();

const fn = ['filename1', 'filename2', 'filename3'];

for (const e of fn) {
  app.get(`/${e}`, (req, res) => {
    res.send(e);
  });
};

app.get(`/filename1`, (req, res) => {
  res.send('test');
});

const port = 1900;
app.listen(port, () => {
  console.log(`http://localhost:${port}/`);
});
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can create one wildcard route listener and add your logic inside of it

const express = require('express');
const app = express();

const fn = ['filename1', 'filename2', 'filename3'];

app.get("/*", (req, res) => {
  // Do your logic inside
  if(fn.includes(req.url.replace('/',''))) return res.send('ok');
  
  res.status(404).send('Not Found');
});


const port = 1900;
app.listen(port, () => {
  console.log(`http://localhost:${port}/`);
});
over 4 years ago · Santiago Trujillo 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!