JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

You're reading for free via Kumar Shubham's Friend Link. Become a member to access the best of Medium.

Member-only story

Let’s Build a MERN Stack E-Commerce Web App

Kumar Shubham
JavaScript in Plain English
9 min readJan 23, 2021

Let’s build a simple E-Commerce website using the MERN stack (MongoDB, Express, React and Node) where users can add items, pay and order.

Image by Roberto Cortese on Unsplash
npm init
npm init
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const config = require('config');
const app = express();
app.use(express.json());
if(process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname,'client','build','index.html'));
});
}
const dbURI = config.get('dbURI');
const port = process.env.PORT || 4000;
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => app.listen(port))
.catch((err) => console.log(err));
{
"dbURI": "YOUR_DATABASE_URI",
}

Further Reading

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Written by Kumar Shubham

SDE @ Wells Fargo | Ex-SWE Intern @ ByteLearn | Student @ IIT BHU | Web Dev | DSA | https://www.linkedin.com/in/shubham1710

Responses (4)

Write a response

Really good article! I would love to read the complete series

Thank you for your sharing, it is very helpful for me to learn full-stack development.
Can I translate your "Let's Build a MERN Stack E-Commerce Web App" series into Chinese and give permission to post it on the HelloGithub(https://hellogithub.com/) community platform?

Really amazed! I was looking for a project with MERN Stack and you have just started that!

Recommended from Medium

Lists

See more recommendations