Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda