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

895
Vistas
How to hide .html extension in a Node.js server?

I'm using express.js in my Node server.

I have a webpage https://example.com/login.html and i want to be able to access it when typing https://example.com/login.

Since i'm used to Apache and PHP i know how to do it using .htaccess file but in Node.js i have no clue.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If there are many HTML files, it may be beneficial to use express.static instead of creating a path for each file:

 app.use(express.static(htmlDir, { extensions: ['html'] }));

where htmlDir points to the directory that contains your HTML files. This also works for subdirectories, eg /pages serves pages.html but /pages/page1 serves pages/page1.html .

Take a look at serve-static for additional options, such as defaulting to index.html or failing with 404 if no files match.

over 4 years ago · Santiago Trujillo Denunciar

0

var express = require('express');
var app = express();
app.set('port', (5000));
app.get('/login', function(req, res) {
    res.render('login'); // no need to use '.html'
});
over 4 years ago · Santiago Trujillo Denunciar

0

It's simple.

Put this at the top of your code

var express = require("express");
var app = express();

And add this to your code

app.get('/login', function(req, res) {
    res.sendFile(__dirname + '/public/login.html'); // replace /public with your directory
});
over 4 years ago · Santiago Trujillo 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