-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (46 loc) · 1.32 KB
/
app.js
File metadata and controls
64 lines (46 loc) · 1.32 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var Post = require('../schema/post');
require('date-utils');
var indexRouter = require('./routes/index');
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
const mongoose = require('mongoose');
var db = mongoose.connection;
db.on('error', console.error);
db.once('open',function(){
console.log('Connect Success');
})
mongoose.connect('mongodb://localhost:27017/Post');
const init = async () => {
while (true) {
if (new Date().toFormat('MI') === "28")
break;
}
const postValue = new Post();
postValue.id = 10;
postValue.date = getCurrentDate();
await postValue.save(function(err, postvalue){
if (err)
return console.log(err);
console.log("Create Success");
});
}
const getCurrentDate = () => {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
var today = date.getDate();
collection_name=year.toString()+month.toString()+today.toString();
return collection_name;
}
init();
setInterval(init, 86390000);
module.exports = app;