Skip to content

Commit c80bb48

Browse files
authored
Create app.js
Created
1 parent 9c63d61 commit c80bb48

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

app.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const express = require('express');
2+
const bodyParser = require('body-parser');
3+
4+
const app = express();
5+
const PORT = process.env.PORT || 3000;
6+
7+
app.use(bodyParser.json());
8+
9+
// Mock data for recommendations
10+
const recommendations = [
11+
{ title: "Use Organic Fertilizers", details: "Organic fertilizers improve soil health and crop yield." },
12+
{ title: "Implement Crop Rotation", details: "Crop rotation helps in maintaining soil fertility." },
13+
{ title: "Adopt Drip Irrigation", details: "Drip irrigation conserves water and increases efficiency." }
14+
];
15+
16+
// Endpoint to get recommendations
17+
app.get('/api/recommendations', (req, res) => {
18+
res.json(recommendations);
19+
});
20+
21+
// Endpoint to get recommendation details
22+
app.post('/api/details', (req, res) => {
23+
const { index } = req.body;
24+
if (index >= 0 && index < recommendations.length) {
25+
res.json(recommendations[index]);
26+
} else {
27+
res.status(404).json({ error: 'Recommendation not found' });
28+
}
29+
});
30+
31+
app.listen(PORT, () => {
32+
console.log(`Server is running on port ${PORT}`);
33+
});

0 commit comments

Comments
 (0)