DEV Community

Balaji
Balaji

Posted on

3 1 1 1 1

How to Run an Angular/React/Vue Build Locally

In this article, I will share how to test production build locally with node.js.

  • Create a file in main directory and provide any name along with .js extension (Example:run-build.js)
  • Copy below code and paste it in your file.
  • Provide build path along with directory name
  • Run this command in command prompt node run-build.js
  • Now your app is running in 9000 port.
const express = require('express');
const path = require('path');
const app = express();

/**
 * Instead of build provide your build directory.
 */
app.use(express.static(path.join(__dirname, 'build')));

app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build ', 'index.html'));
});

var server = app.listen(9000, () => {
    var port = server.address().port;
    console.log('App listening at http://localhost:' + port);
    require('child_process').exec(`start http://localhost:${server.address().port}`);
});
Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay