Categories
JavaScript Answers

How to run a Node express server using webpack-dev-server?

Spread the love

To run a Node express server using webpack-dev-server, we run the webpack-dev-server command.

For instance, we write

const express = require("express");
const app = express();

require("./_routes")(app);
app.set("port", 8080);
app.listen(app.get("port"), () => {
  console.log("Node App Started");
});

to add an Express app in dev-server.js

Then in package.json, we write

{
  "scripts": {
    "start": "webpack --progress --colors",
    "dev-server": "node dev-server.js",
    "dev-client": "webpack-dev-server --port 3000"
  }
}

to add the dev-client script to run "webpack-dev-server in the dev-client script on port 3000.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.