Express + MongoDB + Multer backend for the Vault project.
vault-backend/
├── public/ ← PUT your frontend files here (index.html, style.css, app.js)
├── uploads/ ← uploaded files saved here (auto created)
├── config/
│ ├── db.js ← MongoDB connection
│ └── multer.js ← file upload config
├── models/
│ └── Entry.js ← MongoDB schema
├── routes/
│ └── entryRoutes.js ← all API routes
├── server.js ← main entry point
├── package.json
├── .env ← your secrets (never commit this)
└── .gitignore
| Method | Route | Description |
|---|---|---|
| GET | /health | Check if server is running |
| POST | /api/submit | Submit form data + optional file |
| GET | /api/entries | Get all entries |
| GET | /api/entries/:id | Get single entry |
| DELETE | /api/entries/:id | Delete entry |
Download from https://www.mongodb.com/try/download/community Start it — it runs on port 27017 by default.
Or use MongoDB Atlas (free cloud) — get connection string from atlas.mongodb.com
# Clone or copy project
cd vault-backend
# Install dependencies
npm install
# Create .env file (already created — just edit MONGO_URI if needed)
# For local MongoDB: MONGO_URI=mongodb://localhost:27017/vaultdb
# For Atlas: MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/vaultdbCopy your index.html, style.css, app.js into the /public folder
# Development (auto restart on file change)
npm run dev
# Production
npm start# Add MongoDB repo
sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo << 'EOF'
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF
# Install
sudo yum install -y mongodb-org
# Start and enable
sudo systemctl start mongod
sudo systemctl enable mongod
# Verify
sudo systemctl status mongod# On your Windows PC (Git Bash) — copy project to EC2
scp -i ~/Documents/vault-key.pem -r ./vault-backend ec2-user@YOUR_EC2_IP:~/# SSH into EC2
ssh -i ~/Documents/vault-key.pem ec2-user@YOUR_EC2_IP
# Go to project
cd ~/vault-backend
# Install dependencies
npm install
# Copy frontend files to public folder
# (if your frontend is separate)
cp ~/your-frontend/*.html public/
cp ~/your-frontend/*.css public/
cp ~/your-frontend/*.js public/pm2 start server.js --name vault-backend
pm2 save
pm2 startupcurl http://localhost:5000/healthReplace your localStorage calls with these fetch calls:
// SAVE entry
async function saveEntry(name, email, message, file) {
const formData = new FormData();
formData.append('name', name);
formData.append('email', email);
formData.append('message', message);
if (file) formData.append('file', file);
const res = await fetch('/api/submit', {
method: 'POST',
body: formData // don't set Content-Type, browser sets it automatically
});
const data = await res.json();
console.log(data);
}
// GET all entries
async function getEntries() {
const res = await fetch('/api/entries');
const data = await res.json();
console.log(data.data); // array of entries
}
// DELETE entry
async function deleteEntry(id) {
await fetch(`/api/entries/${id}`, { method: 'DELETE' });
}