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

91
Views
How to run/view ExpressJS server for webpages other than index.html?

So, I want to view/run/display webpages other than the index.html from my public folder which has multiple html files using ExpressJS and NodeJS. Every time I run my server, I can only view the index.html file. Is there a way I can access other html files? I am a beginner and just getting started with the backend part. This is my app.js

 app=express();
const path=require('path');
const Router=express.Router();
const port=process.env.PORT||3000;
require("./db/connectdb");

const static_path=path.join(__dirname,"../../frontend/public");
app.use(express.static(static_path));

app.get('/createelection',(req,res)=>{
    console.log("Create an Election here");
});
app.listen(port,()=>{
    console.log('Server is running at port no. '+ port);
});

My Public Folder

Public
    -index.html
    -createelection.html
    -voterlogin.html
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From a comment on the question:

localhost:3000/createelection

By default the static module will:

  • Give you index.html if you ask for a path ending in /
  • Give you the file you ask for

You are asking for createelection but the file is named createelection.html.

With your current code you need to ask for http://localhost:3000/createelection.html.

Alternatively you can tell Express to try to autocomplete the file extension for you. Look at the documentation for the static module:

extensions: Sets file extension fallbacks: If a file is not found, search for files with the specified extensions and serve the first one found. Example: ['html', 'htm'].

The setting defaults to false

So you would need:

app.use(express.static(static_path, { extensions: true }));
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!