Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

472
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda