A Node.js + Express REST API to collect and manage sensor data such as temperature, humidity, soil moisture, vibration, and location. MongoDB Atlas is used for cloud-based storage.
- β RESTful API with Express.js
- π Cloud database with MongoDB Atlas
- π¦ Data Schema with Mongoose
- π Auto-generated timestamps
- π‘ Sensor data includes:
- Temperature
- Humidity
- Soil Moisture
- Vibration
- Location (Latitude & Longitude)
- Backend: Node.js, Express.js
- Database: MongoDB Atlas
- ODM: Mongoose
Sensor-data-Server/ β βββ models/ β βββ SensorData.js # Mongoose schema β βββ routes/ β βββ sensor.js # API route for data posting/getting β βββ .env # Environment variables (Mongo URI, PORT) βββ server.js # Main server file βββ package.json
- Clone the repo:
git clone https://github.com/your-username/Sensor-data-Server.git
cd Sensor-data-Servernpm install
PORT=3000
MONGO_URI=your_mongo_atlas_connection_string
node server.js
π¬ API Endpoints
Method Endpoint Description
POST /api/sensor Submit sensor data
GET /api/sensor Retrieve all sensor data
π Example Sensor Data JSON
{
"temperature": 24.5,
"humidity": 65,
"soilMoisture": 40,
"vibration": false,
"location": {
"latitude": 28.7041,
"longitude": 77.1025
}
}
π Deployment
When deploying (e.g., on Render, Railway, or Heroku), ensure you:
Use process.env.PORT || 3000 in your server.js.
Store MONGO_URI securely as an environment variable.
π¨βπ» Author
Kushal Sharma
π§ [email protected]
π LinkedIn https://www.linkedin.com/in/kushal-sharma-67378a279/