-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require("express");
const app = express();
var bodyParser = require("body-parser");
const cron = require("node-cron");
const mongoose = require("mongoose");
const productRouter = require("./routes/ProductRoutes");
const productController = require("./controllers/ProductController");
// cron.schedule("*/5 * * * * *",()=>{{console.log('test data generator for weight link on '+ new Date());}})
cron.schedule("*/5 * * * * *", function (req, res) {
insertProduct();
});
//configure mongoose
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/weight_sensor_db_test",
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
(err) => {
if (err) {
console.log(err);
} else {
console.log("Connected to MongoDB");
}
}
);
function insertProduct() {
var req = { name: 'Party',unit:'Kg', createdAt: new Date(), updatedAt: new Date()};
productController.createProductAuto(req);
}
function deleteProduct() {
try {
productController.delAllProduct();
} catch (error) {
console.log(error.message);
}
}
app.use(bodyParser.json());
app.use("/api/products", productRouter);
app.listen(2400, () => {
console.log("Server started at port 2400");
});
module.exports = app;