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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs