Hashnode/mern-starter — an open-source project — sits at 5.1k GitHub stars. ⛔️ DEPRECATED - Boilerplate for getting started with MERN stack
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
MERN is deprecated and is no longer actively maintained.
mern-starter
MERN is a scaffolding tool which makes it easy to build isomorphic apps using Mongo, Express, React and NodeJS. It minimises the setup time and gets you up to speed using proven technologies.
Website
Documentation
Discussions
Road to V3!
We're on our way towards V3, which will bring a few updates to MERN! We are tracking with the following milestones:
V2.4.0 -> Webpack 3 and many fixes Completed : list of changes
Note : Please make sure your MongoDB is running. For MongoDB installation guide see this. Also npm6 is required to install dependencies properly.
Available Commands
npm run start - starts the development server with hot reloading enabled
npm run bs - bundles the code and starts the production server
npm run test - start the test runner
npm run watch:test - start the test runner with watch mode
npm run cover - generates test coverage report
npm run lint - runs linter to check for lint errors
File Structure
Webpack Configs
MERN uses Webpack for bundling modules. There are four types of Webpack configs provided webpack.config.dev.js (for development), webpack.config.prod.js (for production), webpack.config.server.js (for bundling server in production) and webpack.config.babel.js (for babel-plugin-webpack-loaders for server rendering of assets included through webpack).
The Webpack configuration is minimal and beginner-friendly. You can customise and add more features to it for production build.
Server
MERN uses express web framework. Our app sits in server.js where we check for NODE_ENV.
If NODE_ENV is development, we apply Webpack middlewares for bundling and Hot Module Replacement.
Server Side Rendering
We use React Router's match function for handling all page requests so that browser history works.
All the routes are defined in client/routes.js. React Router renders components according to route requested.
// Server Side Rendering based on routes matched by React-router.
app.use((req, res) => {
match({
routes,
location: req.url
}, (err, redirectLocation, renderProps) => {
if (err) {
return res.status(500).end('Internal server error');
}
if (!renderProps) {
return res.status(404).end('Not found!');
}
const initialState = {
posts: [],
post: {}
};
const store = configureStore(initialState);
fetchComponentData(store.dispatch, renderProps.components, renderProps.params).then(() => {
const initialView = renderToString(
<Provider store = {store} >
<RouterContext {...renderProps}/>
</Provider>
);
const finalState = store.getState();
res.status(200).end(renderFullPage(initialView, finalState));
}).catch(() => {
res.end(renderFullPage('Error', {}));
});
});
});
match takes two parameters, first is an object that contains routes, location and history and second is a callback function which is called when routes have been matched to a location.
If there's an error in matching we return 500 status code, if no matches are found we return 404 status code. If a match is found then, we need to create a new Redux Store instance.
Note: A new Redux Store has populated afresh on every request.
fetchComponentData is the essential function. It takes three params: first is a dispatch function of Redux store, the second is an array of components that should be rendered in current route and third is the route params. fetchComponentData collects all the needs (need is an array of actions that are required to be dispatched before rendering the component) of components in the current route. It returns a promise when all the required actions are dispatched. We render the page and send data to the client for client-side rendering in window.__INITIAL_STATE__.
Client
Client directory contains all the shared components, routes, modules.
components
This folder contains all the common components which are used throughout the project.
index.js
Index.js simply does client side rendering using the data provided from window.__INITIAL_STATE__.
modules
Modules are the way of organising different domain-specific modules in the project. A typical module contains the following
.
└── Post
├── __tests__ // all the tests for this module goes here
| ├── components // Sub components of this module
| | ├── Post.spec.js
| | ├── PostList.spec.js
| | ├── PostItem.spec.js
| | └── PostImage.spec.js
| ├── pages
| | ├── PostPage.spec.js
| | └── PostViewPage.spec.js
| ├── PostReducer.spec.js
| └── PostActions.spec.js
├── components // Sub components of this module
| ├── Post.js
| ├── PostList.js
| ├── PostItem.js
| └── PostImage.js
├── pages // React Router Pages from this module
| ├── PostPage
| | ├── PostPage.js
| | └── PostPage.css
| └── PostViewPage
| ├── PostViewPage.js
| └── PostViewPage.css
├── PostReducer.js
└── PostActions.js
Misc
Importing Assets
Assets can be kept where you want and can be imported into your js files or css files. Those fill be served by webpack in development mode and copied to the dist folder during production.
ES6 support
We use babel to transpile code in both server and client with stage-0 plugin. So, you can use both ES6 and experimental ES7 features.
Docker
There are docker configurations for both development and production.
To run docker for development:
docker-compose build # re-run after changing dependencies
docker-compose up
or, if you want to override the web port:
WEB_PORT=<your_custom_port> docker-compose up
To run docker for production:
docker-compose -f docker-compose-production.yml up --build
To reset the database:
docker-compose down --volumes
Make your MERN
In this version, we enabled the mern-cli to clone not only this project but also the variants of mern-starter like one project with MaterialUI or JWT auth. To make your version of MERN, follow these steps
Make your changes. Add a package, add authentication, modify the file structure, replace Redux with MobX or anything else.
In this version, we also added code generators. Blueprints for those generators are located at config/blueprints, and config is located at mern.json. Make sure to edit them if necessary after your made modifications in the previous step. There is a section below which explains how to modify generators.
Next clone mern-cli project
git clone https://github.com/Hashnode/mern-cli
Add your project details to variants.json in the cloned project and send a pull request.
Modifying Generators
mern.json
It contains a blueprints array. Each object in it is the config for a generator. A blueprint config contains the name, description, usage, and files array. An example blueprint config
target-path - location where the file should be generated
parent-path - optional parameter, used if you want to generate the file inside an already existing folder in your project.
Also, target-path supports ejs and the following variables will be passed while rendering,
name - <component-name> input from user
parent - in particular special cases where you need to generate files inside an already existing folder, you can obtain this parent variable from the user. A config using that will look like,
Here, notice the usage. In <module-name>/<component-name>, <module-name> will be passed as parent and <component-name> will be passed as <name>.
helpers - an helper object is passed which include common utility functions. For now, it contains capitalize. If you want to add more, send a PR to mern-cli.
Blueprint files
Blueprints are basically ejs templates which are rendered with the same three variables (name, optional parent and helpers object) as above.
Caveats
FOUC (Flash of Unstyled Content)
To make the hot reloading of CSS work, we are not extracting CSS in development. Ideally, during server rendering, we will be extracting CSS, and we will get a .css file, and we can use it in the html template. That's what we are doing in production.
In development, after all scripts get loaded, react loads the CSS as BLOBs. That's why there is a second of FOUC in development.
Client and Server Markup Mismatch
This warning is visible only on development and totally harmless. This occurs to hash difference in react-router. To solve it, react router docs asks you to use match function. If we use match, react-hot-reloader stops working.
Does Hashnode/mern-starter have a project website?
No homepage URL was recorded for Hashnode/mern-starter in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on Hashnode/mern-starter?
The most recent commit recorded on Hashnode/mern-starter was 3.8 years ago, based on the GitHub push timestamp. The repository has 1.1k forks — one of the better signals of community interest.
How many stars does Hashnode/mern-starter have?
Hashnode/mern-starter has 5.1k GitHub stars — refresh the page for the live number, or check github.com/Hashnode/mern-starter. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is Hashnode/mern-starter written in?
Hashnode/mern-starter is written primarily in JavaScript. GitHub's language field is based on the largest share of bytes in the default branch.
What license does Hashnode/mern-starter use?
Hashnode/mern-starter is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is Hashnode/mern-starter associated with?
GitHub's repository topics for Hashnode/mern-starter: "archived", "deprecated", "obsolete". TopGit's editorial category is open-source.
Where do I read more about Hashnode/mern-starter?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/Hashnode/mern-starter is the definitive source.
Read full README in the tab above.
Is mern-starter worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of mern-starter.