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

477
Views
Can't load/find files on server with node.js, 404 error (not found)

I'm trying to load a script.js and a style.css file on the server. The index.html and index.js work fine, however, there seems to be an error when I try to load the style.css file and script.js file, which I use for backend.

GET http://localhost:4000/script.js net::ERR_ABORTED 404 (Not Found)

All my files are in the same directory, /public.

I already checked the CSS file, and it loads when I display the HTML file when it's not on the server.

This my index.js file:

const express = require('express');
const cors = require('cors');
const fs = require('fs')
const ytdl = require('ytdl-core');
const app = express();

const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'public')))

app.use(cors());

app.listen(4000, () => {
    console.log('Server works at port 4000');
});

app.get('/', function(req,res){
  res.sendFile(__dirname + '/index.html');
}); 

app.get('/download', (req,res) => {
    var URL = req.query.URL;
    res.json({url:URL});
})

The HTML file:

<!DOCTYPE HTML>

<html lang="en">

<head>
  <link href="/style.css" rel="stylesheet" type="text/css"/>
  <meta charset="UTF-8">
  <title>PyTube</title>
</head>

<body>

  <h1>PyTube</h1>
  <input type="url" name="yturl" class="URL-input" id="yturl" placeholder="https://www.youtube.com/watch?v=" required>
  <button class="convert-button">Convert</button>

</body>
</html>

<script src="script.js"></script>

I've tried a bunch of things and trying things with __dirname and paths, but I can't find the issue or fix it.

about 4 years ago · Juan Pablo Isaza
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!