DEV Community


Posted on

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

Top comments (0)