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

212
Views
Node.js express can not get the css and js file

Here is my main.ts file I can not get my css and js file enter image description here

import express from 'express';
import {Request,Response} from 'express';
import expressSession from 'express-session';
import path from 'path';

const app = express();


// set session 
app.use(expressSession({
    resave:true,
    saveUninitialized:true
}));

// teach the server to go to the main page//
app.get("/", (req: Request, res: Response) => {
  res.sendFile(path.resolve(__dirname, "../frontend/public/index.html"));
});



app.use(express.static('public'))

const PORT = 8080;

app.listen(PORT, () => {
    console.log(`Listening at http://localhost:${PORT}/`);
});

And here is my file structure enter image description here here is my html file enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

First things first, you shouldn't post the app secret in a public forum. Second, can you post your index.html file? Chances are it incorrectly loads the JS and CSS files. Third, you can import default and class exports from a package in one line. Change

import express from 'express';
import {Request,Response} from 'express';

to

import express, { Request, Response } from 'express';
about 4 years ago · Juan Pablo Isaza Report

0

seems from the screenshot that your public folder is empty. you seem to have the index.html and other files in your frontend folder and not in the public folder. your index.js and your index.html are on the same level. so your path does not resolve correctly if you resolve it from the index.js file

from which file are you resolving the path? from index.js or main.ts?

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!