Set Up Your MEVN Environment
By the end of this lesson you will have every tool for MEVN development installed, a notenest project with a Vue client and an Express server, and one command that starts both. You will also know the three set-up problems that stop most beginners, and how to fix each one in a minute.
What you should know first: What Is the MEVN Stack? and how to type commands in a terminal. For deeper install help on each tool, see Install Node.js, Install MongoDB, mongosh & Compass and Set Up Vue: CDN & Vite. Versions checked for this lesson: Node.js 26.13 LTS, npm 11, create-vue 3.24.0, Vite 8.3.8, Vue 3.5, Express 5.3.0, Mongoose 9.12.1 and MongoDB 9.0.
What you will install
| Tool | Why you need it | Where to get it |
|---|---|---|
| Node.js 26 LTS (includes npm) | Runs the server, Vite and every build tool | nodejs.org, the "LTS" download |
| MongoDB 9.0 | Stores the notes | MongoDB Community Server, or a cloud database on MongoDB Atlas |
| MongoDB Compass or mongosh | Lets you look inside the database | Comes with the MongoDB downloads |
| Git | Saves your work and keeps secrets out of history | git-scm.com |
| VS Code with the "Vue (Official)" extension | Syntax help for .vue files | code.visualstudio.com |
LTS means Long Term Support. An LTS version of Node.js gets security fixes for years, so servers and courses use it. The "Current" release is for trying new features.
Step 1: Install Node.js 26 LTS
Download the LTS installer from nodejs.org and run it with the default options. Then open a new terminal and check:
node -v
npm -vThe first line should start with v26. and the second with 11.. If node -v shows an older version, such as v22.14.0, the tools in this course will complain. Here is what we saw when we ran create-vue on Node.js 22.14:
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: 'create-vue@3.24.0',
npm warn EBADENGINE required: { node: '^22.18.0 || >=24.12.0' },
npm warn EBADENGINE current: { node: 'v22.14.0', npm: '10.9.2' }
npm warn EBADENGINE }EBADENGINE means "this package says it needs a different Node.js version". It is only a warning, and the scaffold still worked, but the right fix is to install the current LTS. Vite 8 needs Node.js 20.19 or 22.12 and newer, and Mongoose 9 needs 20.19 or newer, so an up-to-date LTS keeps every tool happy.
Step 2: Get a MongoDB database
You have two good options. Both give you a connection string: one line that tells the server where the database is and how to log in.
- Local MongoDB. Install MongoDB Community Server 9.0. It runs as a background service on port 27017. Your connection string is
mongodb://127.0.0.1:27017/notenest. The last part,notenest, is the database name; MongoDB creates it when you first save a note. - MongoDB Atlas. A hosted database in the cloud, with a free tier for learning (check the Atlas pricing page for the current limits). Atlas gives you a string that starts with
mongodb+srv://and contains a username and password.
Write 127.0.0.1, not localhost, for a local database. On some machines localhost resolves to the IPv6 address ::1 first, while MongoDB listens only on IPv4 by default, and the connection is refused.
For Atlas, follow two security rules from day one. Create a database user just for this app, with the readWrite role on the notenest database only, not an admin user. And in "Network Access" allow only your own IP address, not 0.0.0.0/0 (the whole internet).
Step 3: Create the project folder and .gitignore
mkdir notenest
cd notenest
git initBefore you create any .env file, create .gitignore in the notenest folder with these lines:
node_modules/
dist/
.env
.env.*
!.env.exampleThe ! line makes an exception: .env.example, which holds only sample values, may be committed. Doing this first matters. Once a password is committed, it stays in Git history even if you delete the file later, so you would have to change the password.
Step 4: Scaffold the Vue client
Scaffolding means generating the starting files of a project. create-vue is the official scaffolding tool for Vue. Run it from inside notenest:
npm create vue@latest client -- --router --pinia --bareThe -- passes the flags to create-vue instead of npm. --router adds Vue Router, --pinia adds Pinia (the official store library), and --bare leaves out the demo components so you start clean. Without flags, create-vue asks you the same questions one by one. We kept JavaScript instead of TypeScript to keep the focus on how the stack fits together.
┌ Vue.js - The Progressive JavaScript Framework Scaffolding project in C:\projects\notenest\client... │ └ Done. Now run: cd client npm install npm run dev | Optional: Initialize Git in your project directory with: git init && git add -A && git commit -m "initial commit"
(Your folder path will differ; we shortened ours. Skip the Git hint: the repository already lives one level up, in notenest.) Install the client's packages:
cd client
npm install
cd ..added 154 packages, and audited 155 packages in 52s 47 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
Step 5: Create the Express server
The server is a plain Node.js project. Make the folder, create package.json, switch it to ES modules and install the four packages it needs:
mkdir server
cd server
npm init -y
npm pkg set type=module
npm install express mongoose cors helmetadded 86 packages, and audited 87 packages in 1m 33 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
Express handles requests, Mongoose talks to MongoDB, cors controls which websites may call the API, and helmet adds security headers. Now add two scripts:
npm pkg set scripts.dev="node --watch --env-file=.env src/server.js"
npm pkg set scripts.start="node src/server.js"--watch restarts the server whenever you save a file. --env-file=.env loads settings from the .env file, built into Node.js, so you do not need the older dotenv package. The start script has no --env-file on purpose: in production the hosting service provides the variables.
Create server/.env:
PORT=3000
MONGODB_URI=mongodb://127.0.0.1:27017/notenest
CLIENT_ORIGIN=http://localhost:5173Then a first server/src/server.js, just enough to prove the server runs. The next two lessons split it into proper files.
import express from 'express'
const app = express()
const port = Number(process.env.PORT ?? 3000)
app.get('/api/health', (req, res) => {
res.json({ status: 'ok' })
})
app.listen(port, (error) => {
if (error) throw error
console.log(`NoteNest API listening on http://localhost:${port}`)
})Start it with npm run dev and, in a second terminal, ask for the health check:
> server@1.0.0 dev > node --watch --env-file=.env src/server.js NoteNest API listening on http://localhost:3000
curl http://localhost:3000/api/health{"status":"ok"}Ask for /api/notes instead and Express answers with a small HTML page saying Cannot GET /api/notes. That route does not exist yet, and the HTML error is Express's default. In Build a REST API with Express 5 you replace it with the JSON error shape.
Step 6: One command for both halves
Running two terminals every day gets tiring. Go back to the notenest folder and give it a small package.json of its own:
{
"name": "notenest",
"private": true,
"scripts": {
"dev": "concurrently -n api,web -c blue,green \"npm run dev --prefix server\" \"npm run dev --prefix client\"",
"install:all": "npm install --prefix server && npm install --prefix client"
}
}Then install concurrently, a small tool that runs several commands and labels their output, and start everything:
npm install -D concurrently
npm run devHere is a real run from our machine, taken after the MongoDB lesson was finished (so you also see the database line). We removed some blank lines:
[api] > server@1.0.0 dev [api] > node --watch --env-file=.env src/server.js [web] > client@0.0.0 dev [web] > vite [api] MongoDB connected: notenest on 127.0.0.1 [api] NoteNest API listening on http://localhost:3000 [web] Port 5173 is in use, trying another one... [web] Port 5174 is in use, trying another one... [web] [web] VITE v8.3.8 ready in 16630 ms [web] [web] ➜ Local: http://localhost:5175/ [web] ➜ Network: use --host to expose [web] ➜ Vue DevTools: Open http://localhost:5175/__devtools__/ as a separate window
Two other projects were already using ports 5173 and 5174, so Vite moved to 5175. On a fresh machine you will see http://localhost:5173/. Watch for this line: if Vite moves, the address in CLIENT_ORIGIN no longer matches, and the CORS check you add in the next lesson will block calls from the other origin. Close the old dev server, or update CLIENT_ORIGIN.
install:all is for a fresh clone: one command installs both halves. The "ready in" time also varies; ours was slow because many programs were running.
A quick check without any install
Vue also runs from a CDN with no build step, which is handy for checking an idea before you add it to the real project. This page uses the same Composition API that NoteNest's .vue files use. Type a title and watch the preview and counter update:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>NoteNest quick check</title>
<script src="https://cdn.jsdelivr.net/npm/vue@3.5.44/dist/vue.global.prod.js"></script>
<style>
body { font-family: system-ui, sans-serif; margin: 16px; max-width: 30rem; }
label { display: block; margin-top: 8px; }
input { width: 100%; padding: 4px; }
.warn { color: #b00020; }
</style>
</head>
<body>
<div id="app">
<h1>New note</h1>
<label for="title">Title</label>
<input id="title" v-model="title" maxlength="140">
<p :class="{ warn: tooLong }">{{ title.trim().length }} / 120 characters</p>
<p v-if="tooLong" class="warn">The server will reject titles longer than 120 characters.</p>
<h2>Preview</h2>
<p>{{ title.trim() || '(no title yet)' }}</p>
<p>Vue version: {{ version }}</p>
</div>
<script>
const { createApp, ref, computed } = Vue;
createApp({
setup() {
const title = ref("Revise Vue Router before Friday");
const tooLong = computed(() => title.value.trim().length > 120);
return { title, tooLong, version: Vue.version };
}
}).mount("#app");
</script>
</body>
</html>The 120-character limit is the same one the server will enforce in MongoDB & Mongoose Models. Checking in the browser gives fast feedback; checking on the server is what actually protects the data.
Common mistakes
- An old Node.js version.
EBADENGINEwarnings or strange syntax errors usually meannode -vis below the LTS. Install Node.js 26 LTS and open a new terminal. - Port already in use. If another program holds port 3000, the server stops with
Error: listen EADDRINUSE: address already in use :::3000. Close the other server, or set a differentPORTin.env. - Running
npm installin the wrong folder. Server packages belong inserver/, Vue packages inclient/. Check your terminal's folder before installing. - Creating
.envbefore.gitignore. Onegit add .later, the database password is in history. - Using
localhostin the MongoDB connection string. Use127.0.0.1to avoid the IPv6 mismatch.
Interview questions
1. Why do teams use the LTS release of Node.js for servers?
LTS releases receive security and bug fixes for a long, published period, and libraries test against them. Production servers need that stability more than the newest features, so teams upgrade from one LTS line to the next on a schedule.
2. What does node --env-file=.env do, and why is it not used in the start script?
It makes Node.js load the key-value pairs in .env into process.env before the program starts, without the dotenv package. In production the platform injects environment variables itself, and there should be no .env file on the server, so the start script runs plain node.
3. What is the purpose of .env.example?
It lists every setting the app needs, with safe sample values, and is committed to Git. A new developer copies it to .env and fills in real values, while the real .env with secrets stays out of the repository.
4. Why give the app its own database user instead of using an admin account?
This is the principle of least privilege. If the app is compromised, an attacker can only read and write the app's own database, not drop other databases, create users or change server settings.
Key points
- Install Node.js 26 LTS;
EBADENGINEwarnings mean your Node.js is older than a package expects. - Use local MongoDB 9.0 (
mongodb://127.0.0.1:27017/notenest) or Atlas with a least-privilege user and an IP allow-list. - Create
.gitignorewith.envbefore any secret exists. npm create vue@latest client -- --router --pinia --barescaffolds the Vue client; the server isnpm init -yplus Express, Mongoose, cors and helmet.node --watch --env-file=.envgives auto-restart and.envloading with no extra packages.- A root
devscript with concurrently starts both halves; check which port Vite really used.
Exercise
Set up NoteNest on your own machine exactly as in this lesson. Then make two changes and test them: move the API to port 4000 (update every place that must change), and add a GET /api/version route that returns { "name": "notenest", "node": "<the running Node.js version>" }. List the files you edited.
Show solution
Change PORT=4000 in server/.env. The fallback in server.js can stay at 3000, because .env wins. The Vite proxy you add in the next lesson must then point at http://localhost:4000. The new route goes in server/src/server.js:
app.get('/api/version', (req, res) => {
res.json({ name: 'notenest', node: process.version })
})process.version is the running Node.js version as a string such as v26.13.1. Files edited: server/.env and server/src/server.js. Because the dev script uses --watch, saving server.js restarts the server, but a change to .env needs a manual restart (press Ctrl+C and run npm run dev again).
Quick Quiz
1. Which part of npm create vue@latest client -- --router --pinia --bare sends the flags to create-vue rather than to npm?
Everything after -- is passed to the create-vue command itself.
2. Why should the local MongoDB connection string use 127.0.0.1 instead of localhost?
Using the IPv4 address avoids a refused connection on some machines.
3. The server prints EADDRINUSE on start. What is the most likely cause?
Stop the other program or change PORT.
4. Where should the database password for NoteNest live during development?
Only the server needs it, and the real .env is never committed.
Learn MEVN Stack with a mentor
Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
