Kickstart Your Project : Server Setup & Core Installations

Building with the MERN stack (MongoDB, Express.js, React, and Node.js) demands more than just writing code, it starts with setting up a solid and efficient server environment. In this blog, we'll walk through the critical first steps: configuring your server with Express.js, setting up MongoDB, initializing your Node.js environment, and installing all necessary core packages.
Whether you're starting a new MERN project or looking to sharpen your backend fundamentals, this guide will give you a clear, professional roadmap to set up your project correctly from day one.
If you’re completely new to the MERN stack and want a deeper understanding of its architecture and workflow, I recommend checking out my earlier blog post where I introduced the core concepts of the MERN stack in depth.
Now, let’s dive into the essential installations and server setup you need to kickstart your MERN journey with confidence
Before we build anything, the first thing we need is a server for our backend
You can think of it like this:
👉 Backend = the whole brain and muscles that do the work behind the scenes.
👉 Server = the heart (or life engine) that keeps it all running and responding.
Imagine you open TikTok and scroll through funny videos. Or you open Facebook and like your friend’s vacation photos.
Behind the scenes, servers are the real MVPs making all that magic happen.
A server is basically what stores, processes, and sends information whenever you ask for it.
It’s like TikTok’s or Facebook’s personal butler, always ready, always listening.
Think about how you use TikTok or Facebook:
When you upload a video, post a status, or react to a friend's photo, your device isn't talking directly to other people’s devices.
Instead, your actions are sent to powerful backend servers owned by TikTok or Facebook
These servers process your actions, saving your video, updating the number of likes, fetching new posts for your feed, and then respond by sending updated information back to your app
Without servers, there would be no way for your app to access or share real-time information — TikTok videos wouldn't load, Facebook feeds would stay blank, and messages would never deliver
it's the heartbeat of online platforms, making sure millions of users can interact with content, each other, and the world, seamlessly and instantly
HOW TO SETUP YOUR FIRST EVER SERVER?
i got you covered!!
Setting up your first server sounds scary, but trust me, it is very easy
Install Node.js (or any backend environment)
Most modern servers are built with languages like Node.js (JavaScript), Python, or PHP.
For beginners, Node.js is super popular and friendly.
✅ Download and install Node.js from nodejs.org.
✅ It will also install npm (Node Package Manager), which helps you install extra tools easily
Just simple go to the nodejs official website
click on the button “Download Node.js(LTS)”
downloaded it?
Nice!
2. Create a New Project Folder
Now, we create a new folder anywhere on our computer and let’s call it MERN STACK BEGINNERGS.
Now open your Vscode, then open that folder you just created on your Vscode
once you opened the folder on your vscode, open your terminal ctrl + ~
just type in mkdir Backend
kingsleypc@Adams-MacBook-Air MERN STACK BEGINNERGS % mkdir Backend
This command creates new directory as seen below
if you have gotten to this point, Congrats on making it this far! You've officially created your first backend directory, and it’s only the beginning.
Next thing we do is to navigate to the directory we just created
go to our Terminal
and type in this command to navigate to the directory
kingsleypc@Adams-MacBook-Air MERN STACK BEGINNERGS % cd Backend
Great, now we are in the Backend directory
Then type
kingsleypc@Adams-MacBook-Air Backend % % node -v
This command checks which version of Node.js you have installed. It's like tapping Node.js on the shoulder and asking, "Are you there?" If Node is properly installed, it will reply with its version number.
Note: Make sure Node.js is properly installed on your computer. I won’t be covering the installation steps here, but you can easily find plenty of guides online to help you set it up easily
Next, initialize your Node project:
still on your terminal
run this command
npm init -y
This quickly sets up a basic project for you
you should see a package.json file under your Backend folder
Great!
Install Express (a simple server framework)
Express is a small but powerful tool (called a "framework") for Node.js that makes building a server way easier and faster.
Without Express, if you tried to build a server using pure Node.js, you would have to write a lot of complicated code just to handle simple things like routes, requests, and responses.
Express simplifies all that
Run this in your terminal:
npm install express
once installation is complete
Create Your Server File
Next, inside your backend folder, create a new file called
server.js
.
This is where we’ll write the code to set up your server.Important:
You can actually name this file anything you want (likeapp.js
,index.js
, or evenbanana.js
but
server.js
is a common name i use so it's easy to understand what the file is for
Now, let’s write the code that will make our server "wake up" and start listening for incoming requests!
Inside your server.js
file (or whatever you named it), add this:
//server.js
const express = require("express"); //we import express
const app = express();
const PORT = process.env.PORT_NUMBER || 4000;
app.listen(process.env.PORT_NUMBER, () => {
console.log(`Connected to the server and listening on port ${PORT}`);
});
Let's break this down:
✅ const express = require("express");
Here, we are importing Express into our project.
In backend development (especially with Node.js), we use the require
keyword whenever we want to bring in or import an external package or module or other exported files that we need
✅ const app = express();
We are creating an instance of Express.
This app
variable will be our main server object — we’ll use it to define routes, handle requests, and more.
as we code along, you will see what i mean
✅ app.listen(process.env.PORT_NUMBER, () => { ... });
This line tells our server:
"Hey, start listening on a specific port for incoming connections."
process.env.PORT_NUMBER
means: "look for a PORT_NUMBER in your system's environment variables."The function inside
() => {}
runs when the server successfully starts.console.log("Connected to the server and listening on port 4000");
simply prints a success message to your terminal so you know everything is workingImportant Note:
Right now, the message says "listening on port 4000" —
but the actual port depends on the value insideprocess.env.PORT_NUMBER
.👉 If you want to make it even safer (so it defaults to 4000 if no PORT_NUMBER is set), you can slightly tweak it like this:
const PORT = process.env.PORT_NUMBER || 4000; app.listen(PORT, () => { console.log(`Connected to the server and listening on port ${PORT}`); });
This way, your server will always have a port to listen on, even if no environment variable is set yet!
We imported Express.
We created an
app
to manage our server.We told the app to listen on a port for incoming connections.
We confirmed that the server started successfully with a console message.
✅ Your server is now alive and ready to handle requests!
Install Nodemon
Why Nodemon is Important?
When you're building your server, every time you make a small change on our files, you normally have to stop your server and restart it manually to see the updates.
That gets really annoying, really fast. 😩
Nodemon is a tool that saves you from that pain.
It watches your project files, and automatically restarts your server whenever you make a change.In simple words:
Without Nodemon → You have to keep stopping and restarting your server by hand.
With Nodemon → You just save your file, and Nodemon restarts the server for you like magic. ✨
Would you rather wash dishes one by one manually, or have a dishwasher do it for you automatically? 🤔
Nodemon is your dishwasher for backend development. 🚀
Get it?
Nice
To install nodemon, simply Run this on your terminal
npm i nodemon
Once Nodemon is installed, locate your package.json
file and add this script to make running your server easier
"dev": "nodemon server.js"
so your package.json file should look like this:
Why Did We Add "dev": "nodemon server.js"
?
We added this line inside the "scripts"
section of our package.json
to make our lives easier.
Instead of typing nodemon server.js
in our terminal every time we want to start our server,
now we can simply run:
npm run dev
✅ It’s shorter.
✅ It’s cleaner.
It’s just a shortcut to start our server with Nodemon, the easy way. 🚀
Great job so far!
At this point, we have successfully installed:
Express — the framework that makes building servers with Node.js much easier.
Nodemon — the tool that automatically restarts the server whenever we make changes to our files.
Now, let's run our server:
Open your terminal and run the following command:
npm run dev
If everything is set up correctly, you should see the console message you added earlier. something like:
Connected to the server and listening on port 4000
🎉 Congratulations!
Great job, you've just created your very first backend server!
That was fun, right? You’ve taken an important first step into the world of backend development.
Setting up a basic server is the foundation of almost everything you’ll build going forward, and now you have that foundation in place. 🚀
In the next part of this series, we’ll dive deeper into how a backend project is properly structured.
You'll learn about the different folders and files we usually create, why they are important, and how everything works together.
We’ll also start building some real APIs to handle requests like a true backend developer!
Trust me, it only gets more exciting from here. 🔥
Stay tuned and keep coding!
See you in the next chapter 🚀💻🔥
Subscribe to my newsletter
Read articles from Okeze Kingsley directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Okeze Kingsley
Okeze Kingsley
I am a Frontend Developer position. With a solid background in web development (3+ years of experience) and a passion for creating exceptional user experiences, I am excited about the opportunity to contribute my skills to your team. Throughout my career, I have honed my expertise in ensuring that I can craft responsive and visually appealing websites. I am well-versed in modern frontend frameworks and libraries, allowing me to stay at the forefront of industry trends and best practices. Collaboration is a cornerstone of my work ethic, and I thrive in team environments. I enjoy turning design concepts into functional, user-friendly interfaces and have a keen eye for detail when it comes to optimizing for performance and accessibility.