Step-by-Step Guide to Creating A MERN Application for Total Beginners — Part One

1. Setup Your Folders

3 min readNov 10, 2022

Open up your terminal. In your terminal, type:

mkdir project — create a folder named project
cd project — move into project folder
mkdir client server — make two folders named client and server
cd server — move into server folder
touch index.js — create an entry point file with name of index in the format of javascript

What is an entry point?
An entry point is the file which initializes the app and from which execution starts.

2. Setting Up & Installing npm Packages

Make sure your are in your server folder and you have npm installed. If not, google download npm and you will find instructions.

Next, in your terminal, type:

npm init -y set up an npm package with all the defaults
npm i nodemon express dotenv mongoose install our project dependencies
code . to open up the folder in your code editor

npm init -y

In your server folder you will see a file named package.json that is created by npm. Open up that file. In the scripts section, type:

“start” : “nodemon index.js”

Add “start” : “nodemon index.js” to your scripts in package.json

What is npm?
A database of JavaScript packages, each comprised of software and metadata.

Why do we need npm?
To download packages to use in their own projects. We also use it to create a package.json file that will have information about your project such as name, version, author, license, etc. and to manage and keep track of all your dependencies.

What are packages?
A package is a file or directory that is described by a package.json file.

Bonus: What are modules?
A module is a single JavaScript file that has some reasonable functionality. Packages can be a directory with one or more modules.

What are dependencies?
Packages required by your application in production.

3. Setting Up Express

In your index.js file, type:

const express = require(‘express’); load express
const app = express(); instantiates express and assigns app variable to it
const PORT = 3000;
app.listen(PORT, () => console.log(`Server is running on ${PORT}`))

What is express use for?
Express is used for building web applications quickly and easily. It has features such as routing, templating, debugging and middleware.

Why do we need to require it?
In order to use it.

What is require() in node.js express?
The require() statement reads a JavaScript file, executes it, and then proceeds to return the export object. It’s a built-in function with a special purpose that is to to load modules.

What is a port?
A number assigned to uniquely identify a virtual point where network connections start and end.

Bonus: What is middleware?
Middlewares are codes that execute before an HTTP request reaches the route handler or before a client receives a response, giving the framework the ability to run a typical script before or after a client’s request.

With middleware, developers can plug in scripts to intercept the flow of the application, for example, developers can use middleware to check if a user is successfully logged in or logged out.