Why choose MERN stack?

Divyani Tyagi
Jul 5 · 9 min read
Image for post
Image for post

MongoDB

{ “id”: objectid=(“7basd3366g789fffff”),  “title”: “About MONGODB”,  “content”: “MongoDB is a non relational database”,  “comments: [
{“name” : “abc”, “email”: “abc@gmail.com”},
{“name” : “xyz”, “email”: “xyz@gmail.com”}
]
}
Image for post
Image for post
const mongoose = require('mongoose');
const validator = require('validator');// Defining User collection schema structure.
// We have name, email, password field.const userSchema = mongoose.Schema({
name: {
type: String,
require: true,
trim: true
},
email: {
type: String,
required: true,
trim: true,
lowercase: true,
unique: true,
validate(value){
if(!validator.isEmail(value)){
throw new Error('Email is invalid')
}
}
},
password: {
type: String,
required: true,
trim: true,
minlength: 7,
validate(value){
if(value.toLowerCase().includes('password')){
throw new Error('Password cannot contain "Password"')
}
}
}

})const User = mongoose.model('User', userSchema)
module.exports = User

Express.js

React.js

import React from 'react'; 
const SearchBox = ({ searchfield, searchChange }) => {
return (
<div className='pa2'>
<input
className='pa3 ba b--green bg-lightest-blue'
type='search'
placeholder='search robots'
onChange={searchChange}
/>
</div>
);
}
export default SearchBox;
npx create-react-app helloreact
cd helloreact
npm start
Image for post
Image for post
import React, { Component } from 'react';

class App extends Component {
render() {
return (
<div className="App">
<h1>Hello World!</h1>
</div>
);
}
}

export default App;
Image for post
Image for post
This is how our helloreact app will look like when we render h1 element.

Node.js

Lets Do Hello World! with NodeJs

$ npm i express
const express = require('express');
const app = express();const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
req.send('Hello World');
}
app.listen(port, () => {
console.log('Server is up to ' + port)
}
Image for post
Image for post
Image for post
Image for post

Other Features with MERN

import React from ‘react’; 
const Card = ({ name, email, id }) => {
return (
<div className=’tc grow bg-red br3 pa3 ma2 dib bw2 shadow-5'>
<img alt=’robots’ src={`https://robohash.org/}/>
<div>
<h2>{name}</h2>
<p>{email}</p>
</div>
</div>
);
}
export default Card;

MEAN VS MERN

Image for post
Image for post

Summary

Image for post
Image for post

Aeologic

This publication contains all the major blogs that are on…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store