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

134
Vistas
Express server not serving my bundle.js

I'm trying to serve a bundle.js file from my React components but am unsure why the file isn't being served. I'm using Express and have a project with these files:

project
    /dist
        bundle.js
    /views
       /home
          index.ejs
    /routes
       index.js
    app.js

In my app.js, I tried to serve bundle.js:

DIST_DIR = path.join(__dirname, 'dist')
app.use(express.static(DIST_DIR));

My simple views/home/index.ejs looks like:

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <link rel='stylesheet' href='css/styles.css'/>
</head>

<body id="main-page">
    <div class="container">
    </div>
  <script src="bundle.js"></script>
</body>

</html>

I finally GET the page in my routes/index.js using:

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
  res.render('home/index.ejs');
});

module.exports = router;

And this is my app.js

var express = require("express");
    path = require("path"),
    cookieParser = require('cookie-parser'),
    bodyParser = require('body-parser');

    index = require('./routes/index'),
    app = express();

    DIST_DIR = path.join(__dirname, 'dist'),
    app.use(express.static(DIST_DIR));
    app.use('/', index);
    app.set('views', path.join(__dirname, 'views')),
    app.set('view engine', 'ejs');

    module.exports = app;

But I come back with an error: empty response whenever I try to load the page. I'm missing something and am unsure where. Any help would be appreciated.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Usually you have a index.html that contains a div where everything gets loaded. If you want to build everything from scratch see something like the following, http://andrewhfarmer.com/build-your-own-starter/#0-intro

Or if you want to spend less time tooling around, and more time with react, then look at using the https://github.com/facebookincubator/create-react-app

about 4 years ago · Santiago Trujillo Denunciar
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