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

893
Views
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 answers
Answer question

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 Report

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 Report

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 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!