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

478
Vistas
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
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