A production-ready Node.js + Express backend that tracks website visitors and sends real-time email notifications via Nodemailer.
visitor-tracker/
├── server.js ← Entry point
├── routes/
│ └── track.js ← POST /track endpoint
├── services/
│ ├── emailService.js ← Nodemailer email sender
│ ├── parserService.js ← UA / device / browser parser
│ └── cooldownService.js ← In-memory spam prevention
├── .env.example ← Copy → .env and fill values
├── .gitignore
└── package.json
# 1. Clone / download the project
cd visitor-tracker
# 2. Install dependencies
npm install
# 3. Set up environment variables
cp .env.example .env
# Edit .env with your email credentials
# 4. Start the server
npm start # production
npm run dev # development (auto-restart with nodemon)Logs a visitor and sends an email notification (respecting cooldown).
Request body (JSON):
{
"ip": "203.0.113.42",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...",
"platform": "Win32",
"timestamp": "2024-01-15T10:30:00.000Z",
"location": { "city": "Mumbai", "country": "India" }
}Success response:
{ "success": true, "notified": true }Cooldown response:
{ "success": true, "notified": false, "reason": "cooldown" }Returns server uptime — use this for Render's health check.
{ "status": "ok", "uptime": 42.3 }Paste this in your website's HTML to call the tracker:
<script>
fetch("https://YOUR-RENDER-URL.onrender.com/track", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ip: "visitor-ip", // fetch from ipapi.co or similar
userAgent: navigator.userAgent,
platform: navigator.platform,
timestamp: new Date().toISOString(),
location: null // pass city/country if you have it
})
});
</script>To get the real visitor IP on the frontend, first call:
const { ip } = await fetch("https://api.ipapi.is/").then(r => r.json());git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/YOUR_USERNAME/visitor-tracker.git
git push -u origin main- Go to https://render.com and sign in
- Click "New" → "Web Service"
- Connect your GitHub repo
- Fill in the settings:
| Setting | Value |
|---|---|
| Name | visitor-tracker |
| Environment | Node |
| Build Command | npm install |
| Start Command | npm start |
| Instance Type | Free |
In Render → your service → "Environment" tab, add:
| Key | Value |
|---|---|
EMAIL_SERVICE |
gmail |
EMAIL_USER |
you@gmail.com |
EMAIL_PASS |
xxxx xxxx xxxx xxxx |
NOTIFY_TO |
your-inbox@example.com |
COOLDOWN_MINUTES |
10 |
Click "Create Web Service" — Render will build and deploy automatically.
Your API will be live at:
https://visitor-tracker.onrender.com
In Render → Settings → Health Check Path, set:
/health
This keeps your service alive and Render knows when to restart it.
Regular Gmail passwords don't work with SMTP. You need an App Password:
- Go to myaccount.google.com
- Security → 2-Step Verification → enable it
- Security → App Passwords
- Generate one for "Mail" / "Other"
- Copy the 16-char password → paste as
EMAIL_PASSin.env
First visit from IP → ✅ Send email
Second visit within 10 min → ⏭️ Skip (cooldown)
Visit after 10+ minutes → ✅ Send email again
The cooldown duration is controlled by COOLDOWN_MINUTES in .env.
MIT — free to use and modify.