{"id":2291,"date":"2022-01-26T09:24:09","date_gmt":"2022-01-26T09:24:09","guid":{"rendered":"https:\/\/lvboard.infostore.in.ua\/?p=2291"},"modified":"2022-01-26T09:24:09","modified_gmt":"2022-01-26T09:24:09","slug":"the-efficient-way-to-create-a-mern-app","status":"publish","type":"post","link":"https:\/\/lvboard.infostore.in.ua\/?p=2291","title":{"rendered":"The Efficient Way to Create a MERN App"},"content":{"rendered":"\n<p id=\"80e8\">Whether you are a newbie or an expert in the programming space, you\u2018ve probably wondered how others developers set up and configure their starting project application.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p id=\"ea49\">This article tackles an efficient and intelligent way to set up a production-ready application. We will look into how to set up a MERN Stack application with tools, frameworks and modules that will allow us to manage the performance, styling, asynchrony, and other essential stuff we need to build a real-world application.<\/p>\n\n\n\n<h2 id=\"273c\">Project Structure<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/miro.medium.com\/max\/290\/1*J0pptyfTBxvX5XE0-RDnpQ.jpeg\" alt=\"\"\/><figcaption>Project Structure<\/figcaption><\/figure>\n\n\n\n<h2 id=\"88fd\"><strong>Initializing <em>package.json<\/em> and installing Node.js modules.<\/strong><\/h2>\n\n\n\n<p id=\"e5cb\">First, create a new folder called <strong>mern-app-setup<\/strong>.<strong> <\/strong>Enter this folder and initialize our full stack application by entering and running this command in your terminal the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>npm init<\/em><\/pre>\n\n\n\n<p id=\"2eab\"><em>You<\/em> will be asked a series of questions to gather meta-information about our project such as name, author and license. Then a <strong><em>package.json<\/em><\/strong> file will be auto generated with your answers and meta-information about the application as well as list of modules dependencies.<\/p>\n\n\n\n<p id=\"fb48\">Alternatively, you can also initialize it using <code><em>yarn init<\/em><\/code><em> <\/em>if you are using yarn package manager. Before running theses commands make sure that you have already installed the latest <a href=\"https:\/\/nodejs.org\/en\/download\/\" rel=\"noreferrer noopener\" target=\"_blank\">Node.js<\/a> , <a href=\"https:\/\/docs.npmjs.com\/downloading-and-installing-node-js-and-npm\" rel=\"noreferrer noopener\" target=\"_blank\">npm<\/a> or <a href=\"https:\/\/classic.yarnpkg.com\/lang\/en\/docs\/install\/\" rel=\"noreferrer noopener\" target=\"_blank\">yarn<\/a> on your local machine. Click on each of those links to know more about the process.<\/p>\n\n\n\n<p id=\"bfc7\">Now, let us install all the necessary dependencies and devDependencies that we need. Open <strong><em>package.json<\/em><\/strong> file and modify the JSON object to add the key modules and dependencies.<\/p>\n\n\n\n<p id=\"2e04\">Dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\"dependencies\": {<br>\"@hot-loader\/react-dom\": \"^17.0.1\",<br>\"express\": \"^4.17.2\",<br>\"react\": \"^17.0.2\",<br>\"react-dom\": \"^17.0.2\",<br>\"react-hot-loader\": \"^4.13.0\"<br>},<\/pre>\n\n\n\n<p id=\"2068\">DevDependencies: Modify<strong> <em>package.json<\/em><\/strong> further to add the following Node modules required during development as devDependencies:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\"devDependencies\": {<br>\"@babel\/core\": \"^7.16.5\",<br>\"@babel\/preset-env\": \"^7.16.5\",<br>\"@babel\/preset-react\": \"^7.16.5\",<br>\"babel-loader\": \"^8.2.3\",<br>\"nodemon\": \"^2.0.15\",<br>\"webpack\": \"^5.65.0\",<br>\"webpack-cli\": \"^4.9.1\",<br>\"webpack-dev-middleware\": \"^5.3.0\",<br>\"webpack-hot-middleware\": \"^2.25.1\",<br>\"webpack-node-externals\": \"^3.0.0\"<br>}<\/pre>\n\n\n\n<p id=\"5eb2\">Save the package.json and run <code><em>npm install<\/em><\/code> from the command line to fetch and add all these modules to the project. With all the necessary modules installed and added to the project, next we will add configuration to compile and run a simple application.<\/p>\n\n\n\n<p id=\"b02c\">Note that you can also install all these modules manually on the command line and work with the latest versions modules dependencies but we use this method just in case you will be reading this article a year or two years from now, so you will have the same code base and modules versions here in case you want to follow along with us.<\/p>\n\n\n\n<h1 id=\"a1d6\"><strong>Configuring Babel, Webpack and Nodemon<\/strong><\/h1>\n\n\n\n<p id=\"e50f\">Now, we will configure our application with Babel, Webpack and Nodemon to compile, bundle and auto-reload the changes in the code during the development. Before diving to these configurations, let us learn a few things about each module.<\/p>\n\n\n\n<h2 id=\"38f6\"><strong>What is Babel?<\/strong><\/h2>\n\n\n\n<p id=\"2900\"><a href=\"https:\/\/babeljs.io\/\" rel=\"noreferrer noopener\" target=\"_blank\">Babel<\/a> is a JavaScript transcompiler that converts edge JavaScript into plain old ES5 JavaScript that can run in any browser (even the old ones). It makes available all the syntactical sugar that was added to JavaScript with the new ES6 specification, including classes, fat arrows and multiline strings.<\/p>\n\n\n\n<h2 id=\"991c\"><strong>What is Webpack?<\/strong><\/h2>\n\n\n\n<p id=\"9b6e\">Webpack is a JavaScript code bundler that traverses the dependency graph of your project (chain of imports you use in your JS files), and creates a static JavaScript file(s) that is ready to be attached to your HTML.<\/p>\n\n\n\n<h2 id=\"d021\"><strong>Configuring Babel<\/strong><\/h2>\n\n\n\n<p id=\"7cd2\">Create a file named <strong>.babelrc<\/strong> in the root directory of the project and add the following JSON with presets and plugins specified:<\/p>\n\n\n\n<p id=\"6644\"><strong><em>mern-app-setup\/.babelrc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"presets\": [<br>    [\"@babel\/preset-env\",<br>  {<br>    \"targets\": {<br>      \"node\": \"current\"<br>    }<br>  }<br>  ],<br>    \"@babel\/preset-react\"<br>  ],<br>  \"plugins\": [<br>    \"react-hot-loader\/babel\"<br>    ]<br>}<\/pre>\n\n\n\n<p id=\"9cf7\">In this configuration, we specify that we need Babel to transpile the latest JavaScript syntax with support for code in a Node.js environment and also React\/JSX code. The react-hot-loader\/babel plugin is required by the react-hot-loader module to compile React components.<\/p>\n\n\n\n<h2 id=\"43ff\"><strong>Configuring Webpack<\/strong><\/h2>\n\n\n\n<p id=\"860c\">First, we will have to configure Webpack to bundle both the client and server code and the client code separately for production.<\/p>\n\n\n\n<p id=\"8c82\">Create <strong><em>webpack.config.client.js<\/em><\/strong>,<strong> <em>webpack.config.server.js<\/em><\/strong>, and <strong><em>webpack.config.client.production.js<\/em><\/strong> files in the project folder.<\/p>\n\n\n\n<p id=\"01ff\">All three files will have the following code structure, starting with imports, then the definition of the config object, and finally the export of the defined config object:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const path = require('path')<br>const webpack = require('webpack')<br>const CURRENT_WORKING_DIR = process.cwd()<br>const config = { ... }<br>module.exports = config<\/pre>\n\n\n\n<p id=\"dc19\">The config JSON object will differ with value specific to client or server-side code, and development versus production code.<\/p>\n\n\n\n<p id=\"d4bd\">In the next sections, we will underline the relevant properties in each configuration instance.<\/p>\n\n\n\n<h2 id=\"bc68\"><strong>Client Side webpack configuration for development<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">const config={<br>name: 'browser',<br>mode: 'development',<br>devtool: 'eval-source-map',<br>entry: [<br>'webpack-hot-middleware\/client?reload=true',<br>path.join(CURRENT_WORKING_DIR,'client\/index.js')<br>],<br>output:{<br>path: path.join(CURRENT_WORKING_DIR, '\/dist'),<br>filename: 'bundle.js',<br>publicPath: '\/dist\/'<br>},<br>module:{<br>rules: [<br>{<br>test: \/\\.jsx?$\/,<br>exclude: \/node_modules\/,<br>use: ['babel-loader']<br>}<br>]<br>},<br>plugins: [<br>new webpack.HotModuleReplacementPlugin(),<br>new webpack.NoEmitOnErrorsPlugin()<br>],<br>resolve:{<br>alias:{<br>'react-dom': '@hot-loader\/react-dom'<br>}<br>}<br>}<\/pre>\n\n\n\n<p id=\"693f\">Now, let us explain each property and method added in this file:<\/p>\n\n\n\n<ul><li>The<strong> name property<\/strong> defines which kind of environment our code will run in. Here we are setting up webpack to bundle the client-side code, so we need to specify <em>browser.<\/em><\/li><li>The<strong> mode <\/strong>sets the node environment to the given value and tells webpack to use its built-in optimizations accordingly. If not set explicitly it defaults to a value of \u201cproduction\u201d.<\/li><li>The <strong>Devtool <\/strong>specifies how source maps are generated, if at all. Generally, a source map provides a way of mapping code within a compressed file back to its original position in a source file to aid debugging.<\/li><li>The <strong>entry <\/strong>point indicates which modules webpack should use to start bundling, in this case with the main.js in the client folder.<\/li><li>The <strong>output <\/strong>property tells webpack where to emit the bundles it creates and how to name these files. In this case, it sets to<strong> <em>dist\/bundle.js<\/em><\/strong><em>.<\/em><\/li><li><strong>The module <\/strong>property<strong> <\/strong>allow webpack to process other types of files and convert them into valid <a href=\"https:\/\/webpack.js.org\/concepts\/modules\" rel=\"noreferrer noopener\" target=\"_blank\">modules<\/a> that can be consumed by our application and added to the dependency graph.<\/li><li>At high level , Loaders have two properties: test and use. The<em> test <\/em>property identifies which file or files should be transformed and the <em>use<\/em> indicates which loader should be used to do the transforming. In our case, we choose to transpile all files with .jsx extensions , and the transpilation tool that we used is <strong>babel-loader.<\/strong><\/li><li>HotModuleReplacementPlugin enables hot module replacement for react-hot-loader.<\/li><li>NoEmitOnErrorsPlugin allows skipping emitting when there are compile errors.<\/li><\/ul>\n\n\n\n<p id=\"8828\">We also add a Webpack alias to point react-dom references to the @hot-loader\/react-dom version.<\/p>\n\n\n\n<p id=\"82e4\">Now, our client-side configuration code is ready to be loaded in the browser from the bundled code in bundle.js. In the next section, we will configure webpack for production.<\/p>\n\n\n\n<h2 id=\"96f7\"><strong>Client side webpack configuration for production<\/strong><\/h2>\n\n\n\n<p id=\"9aad\">In order to bundle the React code to be used in production mode, we need to set up webpack for production by updating the config object with following code:<\/p>\n\n\n\n<p id=\"34ab\"><strong><em>mern-app-setup\/webpack.config.client.production.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const config = {mode: 'production',entry: [path.join(CURRENT_WORKING_DIR, 'client\/index.js')],output: {path: path.join(CURRENT_WORKING_DIR, '\/dist'),filename: 'bundle.js',publicPath: '\/dist\/',},module: {rules: [{test: \/\\.jsx?$\/,exclude: \/node_modules\/,use: ['babel-loader'],},],},};<\/pre>\n\n\n\n<p id=\"f309\">The configuration here is similar to the client-side configuration for development mode, but without the hot-reloading plugin and debug configuration as these will not be required in production.<\/p>\n\n\n\n<h2 id=\"d0d2\"><strong>Server-side webpack configuration<\/strong><\/h2>\n\n\n\n<p id=\"26b3\">In order to configure webpack for server-side, update the <em>webpack.config.server.js<\/em> by adding the following code:<\/p>\n\n\n\n<p id=\"7af6\"><strong><em>mern-app-setup\/webpack.config.server.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const nodeExternals=require('webpack-node-externals');const config={<br>name: 'server',<br>entry: [path.join(CURRENT_WORKING_DIR, '.\/server\/server.js')],<br>target: \"node\",<br>output:{<br>path: path.join(CURRENT_WORKING_DIR, '\/dist\/'),<br>filename: 'server.generated.js',<br>publicPath: '\/dist\/',<br>libraryTarget: 'commonjs2'<br>},<br>externals: [nodeExternals()],<br>module: {<br>rules: [<br>{<br>test: \/\\.js$\/,<br>exclude: \/node_modules\/,<br>use: [ 'babel-loader' ]<br>}<br>]<br>}<br>}<\/pre>\n\n\n\n<p id=\"74c0\">The code inside this file has the same structure as the <strong>webpack.config.client.js<\/strong>. But here we have not defined the mode option and add some additional properties like: <strong><em>libraryTarget<\/em><\/strong> and<strong><em> externals<\/em><\/strong>.<\/p>\n\n\n\n<p id=\"94cf\">Webpack starts bundling from the server folder with<strong> <em>server.js<\/em><\/strong><em>,<\/em> then outputs the bundled code in<em> <\/em><strong><em>server.generated.js<\/em><\/strong> in the dist folder. Now, with the bundling configurations in place, we can add configuration for running these generated bundles automatically on code updates during development using Nodemon.<\/p>\n\n\n\n<h2 id=\"bab0\"><strong>Configuring Nodemon<\/strong><\/h2>\n\n\n\n<p id=\"5023\">Create a file called <strong><em>nodemon.json<\/em><\/strong><em> <\/em>in the folder project and add the following configuration:<\/p>\n\n\n\n<p id=\"6d18\"><strong><em>mern-app-setup\/nodemon.json<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>\"verbose\": false,<br>\"watch\": [ \".\/server\" ],<br>\"exec\": \"webpack --mode=development --config webpack.config.server.js &amp;&amp; node .\/dist\/server.generated.js\"<br>}<\/pre>\n\n\n\n<p id=\"7e64\">This configuration will set up nodemon to watch automatically for changes in the server files during development, then execute compile and build commands as necessary.<\/p>\n\n\n\n<p id=\"9ea2\">Now, we have finished to configure Webpack and Babel. Let\u2019s verify if the configuration is well done by building a simple full stack application.<\/p>\n\n\n\n<h2 id=\"665a\"><strong>Frontend views with React<\/strong><\/h2>\n\n\n\n<p id=\"1c42\">In order to start building the frontend of our application, let\u2019s create a root template file called <strong><em>template.js <\/em><\/strong>in the root directory of our project, which will render the HTML with React components.<\/p>\n\n\n\n<p id=\"5319\">Add the following code in this file: <strong><em>mern-app-setup\/template.js<\/em><\/strong><em>:<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">export default () =&gt; {<br>return `&lt;!doctype html&gt;<br>&lt;html lang=\"en\"&gt;<br>&lt;head&gt;<br>&lt;meta charset=\"utf-8\"&gt;<br>&lt;title&gt;Set up full stack MERN application&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<br>&lt;div id=\"root\"&gt;&lt;\/div&gt;<br>&lt;script type=\"text\/javascript\" src=\"\/dist\/bundle.js\"&gt;<br>&lt;\/script&gt;<br>&lt;\/body&gt;<br>&lt;\/html&gt;`<br>}<\/pre>\n\n\n\n<p id=\"957b\">When the server receives a request to the root URL, this HTML template will be rendered in the browser, and the div element with ID \u201croot\u201d will contain our React component. Next, create a folder called <em>client <\/em>. Inside this folder, create two files:<em> <\/em><strong><em>index.js<\/em><\/strong> and <strong><em>App.js<\/em><\/strong><em>.<\/em><\/p>\n\n\n\n<p id=\"9a9d\">The<strong> <em>index.js<\/em><\/strong> file simply renders the top-level entry React component in the div element in the HTML document:<\/p>\n\n\n\n<p id=\"3716\"><strong><em>mern-app-setup\/client\/index.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React from 'react'<br>import { render } from 'react-dom'<br>import App from \u2018.\/App'render(&lt;App\/&gt;, document.getElementById('root'))<\/pre>\n\n\n\n<p id=\"e4c8\">In this case, the entry React component is the App component imported from <strong><em>App.js<\/em><\/strong><em>:<\/em><\/p>\n\n\n\n<p id=\"552b\"><strong><em>mern-app-setup\/client\/App.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { hot } from 'react-hot-loader\/root';<br>const App=()=&gt;{<br>return (<br>&lt;div&gt;<br>Hello! We are setting up a real world application!<br>&lt;\/div&gt;<br>)<br>}<br>export default hot(App) ;<\/pre>\n\n\n\n<p id=\"79f8\">The <strong><em>App.js<\/em><\/strong> file contains a basic App React component, which is hot-exported to enable hot reloading with react-hot-loader during the development.<\/p>\n\n\n\n<p id=\"62c5\">In order to see the React component rendered in the browser when the server receives a request to the root URL, we need to use the webpack and Babel setup to compile and bundle this code, and also add server-side code that responds to the root route request with the bundled code. We will implement this in the server-side next.<\/p>\n\n\n\n<h2 id=\"0d34\"><strong>Server with Node and Express<\/strong><\/h2>\n\n\n\n<p id=\"aa7e\">In the project folder, create a new folder called <em>server.<\/em> Inside this folder two files called: <strong><em>server.js, devBundle.js<\/em><\/strong><em>.<\/em> The <strong><em>server.js<\/em><\/strong> file will set up the server and the<strong> <em>devBundle.js<\/em><\/strong> file will help to compile the React code using the webpack configuration while in the development mode.<\/p>\n\n\n\n<p id=\"1969\">Now, let us implement the Node-express app which initiates client-side code bundling, starts the server, sets up the path to serve static assets to the client, and renders the React view in a template when a GET request is made to the root route.<\/p>\n\n\n\n<p id=\"28e9\">In order to initialize our Express app, we will first import the Express module and then use this Express app to build the rest of the application. The resume code looks like this:<\/p>\n\n\n\n<p id=\"d4c0\"><strong><em>mern-app-setup\/server\/server.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import express from 'express'<br>const app = express()<\/pre>\n\n\n\n<h2 id=\"68ee\"><strong>Bundling React app during the development<\/strong><\/h2>\n\n\n\n<p id=\"8bf0\">Next, we will initialize webpack to compile the client-side code when the server is running. In <strong>devBundle.js<\/strong>, we will set up a compile method that takes the Express app and configures it to use the Webpack middleware to compile, bundle, and serve code, as well as enable hot reloading in development mode:<\/p>\n\n\n\n<p id=\"586f\"><strong><em>mern-app-setup\/server\/devBundle.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import webpack from 'webpack'<br>import webpackMiddleware from 'webpack-dev-middleware'<br>import webpackHotMiddleware from 'webpack-hot-middleware'<br>import webpackConfig from '.\/..\/webpack.config.client.js'<br>import dotenv from 'dotenv';<br>dotenv.config();const compile = (app) =&gt; {<br>if(process.env.NODE_ENV == \"development\"){<br>const compiler = webpack(webpackConfig)<br>const middleware = webpackMiddleware(compiler, {<br>publicPath: webpackConfig.output.publicPath<br>})<br>app.use(middleware)<br>app.use(webpackHotMiddleware(compiler))<br>}<br>}export default {<br>compile<br>}<\/pre>\n\n\n\n<p id=\"ea19\">We have imported another module called <strong><em>dotenv<\/em><\/strong><em> <\/em>in order to load our environment variables from a<strong> <em>.env<\/em><\/strong><em> <\/em>file into <code>process.env<\/code>. Install it by running <code><em>npm install dotenv<\/em> <\/code>from the command line.<\/p>\n\n\n\n<p id=\"8150\">Now, let us call this compile method in<strong> <em>server.js<\/em><\/strong><em> <\/em>by adding the following lines while in the development mode:<\/p>\n\n\n\n<p id=\"bdbb\"><strong><em>mern-app-setup\/server\/server.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import devBundle from '.\/devBundle'<br>const app = express()<br>devBundle.compile(app)<\/pre>\n\n\n\n<h2 id=\"a880\"><strong>Serving static files from the dist folder<\/strong><\/h2>\n\n\n\n<p id=\"9edb\">Webpack will compile client-side code in both development and production mode, then place the bundled files in the <strong><em>dist<\/em><\/strong> folder. In order to make these static files available on requests from the client side, we will update our <strong>server.js<\/strong> file to serve static files from the <strong><em>dist<\/em><\/strong> folder:<\/p>\n\n\n\n<p id=\"8e6c\"><strong><em>mern-app-setup\/server\/server.js<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import path from 'path'<br>const CURRENT_WORKING_DIR = process.cwd()<br>app.use('\/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))<\/pre>\n\n\n\n<h2 id=\"fa04\"><strong>Rendering templates at the root<\/strong><\/h2>\n\n\n\n<p id=\"3267\">When the server receives a request at the root URL \/ , we will render <strong><em>template.js<\/em><\/strong> in the browser<em>. In order to receive GET requests as \u2018\/\u2019, go to <\/em><strong><em>server.js <\/em><\/strong><em>and<\/em><strong><em> <\/em><\/strong>add the following route-handling code to the Express app:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import template from '.\/..\/template'<br>app.get('\/', (req, res) =&gt; {<br>res.status(200).send(template())<br>})<\/pre>\n\n\n\n<p id=\"123a\">Now let us finalize the server-side app by configuring the Express app to start a server that listens on the specified port for incoming requests:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let port = process.env.PORT || 3000<br>app.listen(port, (err) =&gt;{<br>if (err) {<br>console.log(err)<br>}<br>console.info('Server started on port %s.', port)<br>})<\/pre>\n\n\n\n<p id=\"7b65\">With this code, when the server is running, it will be able to accept requests at the root route and render the React view with the \u201cHello! We are setting up a real-world application!\u201d text in the browser.<\/p>\n\n\n\n<p id=\"72be\">We have finished to configure our MERN Stack application. Now we need to add some scripts in the <em>package.json <\/em>file so that we can run the application.<\/p>\n\n\n\n<p id=\"06ee\"><strong><em>mern-app-setup\/package.json<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\"scripts\": {<br>\"development\": \"nodemon\",<br>\"build\": \"webpack --config webpack.config.client.production.js &amp;&amp; webpack --mode=production --config webpack.config.server.js\",<br>\"start\": \"NODE_ENV=production node .\/dist\/server.generated.js\"<br>} ,<\/pre>\n\n\n\n<p id=\"c229\">To run the code developed so far, and to ensure that everything is working, you can go through the following steps:<\/p>\n\n\n\n<ul><li>Run the application from the command line using <em>npm run development <\/em>to get Nodemon , Webpack and server started for development. After, open the root URL in the browser which is <a href=\"http:\/\/localhost:3000\" rel=\"noreferrer noopener\" target=\"_blank\">http:\/\/localhost:3000<\/a> if you are using your local machine. You should see a page with the text: \u201cHello! We are setting up a real world application!\u201d<\/li><li>Run the application from the command line using <code><em>npm run build<\/em> <\/code>to generate the client and server code bundles for production mode.<\/li><li>Run the application from the command line using <code><em>npm start<\/em> <\/code>to run the bundled code in production.<\/li><\/ul>\n\n\n\n<h2 id=\"4719\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p id=\"216f\">We have finished setting up our MERN application<strong> <\/strong>with Webpack , Babel and Nodemon. But we have not implemented a way to improve our code quality and avoid errors. You can make it by using <a href=\"https:\/\/medium.com\/@merndev\/how-to-set-up-node-js-application-with-eslint-and-prettier-b1b7994db69f\">Prettier<\/a> and <a href=\"https:\/\/medium.com\/@merndev\/how-to-set-up-node-js-application-with-eslint-and-prettier-b1b7994db69f\">Eslint<\/a>. Read this <a href=\"https:\/\/medium.com\/@merndev\/how-to-set-up-node-js-application-with-eslint-and-prettier-b1b7994db69f\"><strong>articles<\/strong><\/a> to have an idea about the process to do this.<\/p>\n\n\n\n<p id=\"0876\">You can find the complete source code in this <a href=\"https:\/\/github.com\/Thomas-Max99\/mern-app-setup\" rel=\"noreferrer noopener\" target=\"_blank\">repository<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you are a newbie or an expert in the programming space, you\u2018ve probably wondered how others developers set up and configure their starting project application.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[186,65],"_links":{"self":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2291"}],"collection":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2291"}],"version-history":[{"count":1,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2291\/revisions"}],"predecessor-version":[{"id":2292,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2291\/revisions\/2292"}],"wp:attachment":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}