---
title: "Comment by Amit Chambial on \"I need to know the flow of this MERN app.\" | Hashnode"
description: "Here Webpack is used to build react jsx. webpack.config.js entryPoint: points to React index.js that resides in client/index.js outputDir : /static/bundle.js( a"
url: "https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086"
---

[Discussion](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1)

Comment [I need to know the flow of this MERN app.](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1)

[Amit Chambial](https://hashnode.com/@amitchambial)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086)

Here Webpack is used to build react jsx.

## webpack.config.js

-   entryPoint: points to React index.js that resides in client/index.js
-   outputDir : /static/bundle.js( after the build is complete the bundle.js go in this folder

## app.js

`app.use("/api/v1/users", userRouter)`

-   all the /api/v1/users request goes to userRouter

`app.use("/*", indexRouter)`

-   all the / request goes to index.js router which in return route it to index.ejs
-   in index.ejs react js bundle file is included , hence routing for /\* will be handled by react routers
-   in index.ejs the react component will be rendered inside `<div id="root"></div>`

> similar to create-react-app we have `public/index.html` there , here we have `index.ejs`

[Dave Rodriguez](https://hashnode.com/@dave447)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086#reply-5ee3b76b98c535462075cf2e)

```
router.get("/*", function (req, res, next) {
  res.render("index", { title: "My App" })
})
```

What is this code block doing? Is it rendering the `index.ejs` file? One more thing, how is /\* will be handled by react routers?

Also could you clarify my doubts on node environment?

In `package.json`, I have this:

```
  "scripts": {
    "start": "NODE_ENV=development nodemon ./bin/www",
    "webpack": "webpack-dev-server --config ./webpack.config.js --mode development"
  },
```

In `app.js`:

```
if (process.env.NODE_ENV === "development") {
  const webpack = require("webpack")
  const webpackConfig = require("./webpack.config")
  const compiler = webpack(webpackConfig)

  app.use(
    require("webpack-dev-middleware")(compiler, {
      noInfo: true,
      publicPath: webpackConfig.output.publicPath,
    })
  )

  app.use(require("webpack-hot-middleware")(compiler))
}
```

I'm confused on how webpack is working here. I know it generates a bundle but how it's working with `env` is just that I could not understand.

Sorry for asking too many questions.

[Amit Chambial](https://hashnode.com/@amitchambial)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086#reply-5ee3bb266c513725202e8bf2)

[Dave Rodriguez](https://hashnode.com/@dave447)

-   this is passing title to ejs and return an HTML having title replaced with My app and with bundle.js imported in it.
-   `/*`is a regex which mean `/a, /user/123` etc will all be catched by `get./*`, means this index.ejs will be returned with bundle.js
-   `/user/amit` => index.ejs => react bundle contains react-router code also. React-router will get the route value from address bar and render the components according to it.

---

-   When we are using npm start it is setting up the NODE\_ENV as development.
    -   Now app.js see the env as development and runs a webpack dev server. Webpack-dev-server provides you live reload facility,meaning when you change react js code , your app ui will change without any need to restart the server. Here the build is stored in memory not in disk and exposed to publicPath ie /static/bundle.js.
-   the webpack command is used to generate the build (bundle) in disk, which can be deployed.

refer this [read](https://github.com/webpack-contrib/webpack-hot-middleware/blob/master/README.md)

[Dave Rodriguez](https://hashnode.com/@dave447)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086#reply-5ee3bea298c535462075cfa5)

[Amit Chambial](https://hashnode.com/@amitchambial) Thanks a lot for answering my questions. Can you add in your answer? I have added a couple of questions more in my previous reply.

[Amit Chambial](https://hashnode.com/@amitchambial)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086#reply-5ee3c21398c535462075cfab)

[Dave Rodriguez](https://hashnode.com/@dave447) Check my prev reply

[Dave Rodriguez](https://hashnode.com/@dave447)

[Jun 12, 2020](https://hashnode.com/posts/i-need-to-know-the-flow-of-this-mern-app/5ee32aee304fa1181a7d6bb1/comment/5ee39582304fa1181a7d7086#reply-5ee3c60798c535462075d00e)

Thank you so VERY much. I really appreciate your time and knowledge. Cheers.[Amit Chambial](https://hashnode.com/@amitchambial)
