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

157
Views
Direct users to the same page with two different paths (Javascript/ nodejs)

I am writing a code that will display a HTML file when the path /contact or /contact-us is entered into the URL. The problem that I am having is that I want to put both of them into the same function rather than have more than one function to do essentially the same thing. I tried finding a solution or help online but I couldn't. What I have tried is to use the or comparison operator for the function to determine the differences between the two paths but that didn't work. Is there a way that I can do this?

This is my code:

app.get('/contact' || '/contact-us', (req, res)=> {
    let path = require('path');
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
    //the or comparison operator does not work and Im not sure if there's another way to do this
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

By putting your list of paths into an array, you can use multiple paths, as explained in this answer. Here is an example for your problem:

app.get(['/contact','/contact-us'], (req, res)=> {
    let path = require('path');
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
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!