-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
90 lines (71 loc) · 2.15 KB
/
server.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const express = require('express');
const mongoose = require('mongoose');
const morgan = require('morgan');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 8080; // Step 1
var cors = require('cors');
app.use(cors());
const MONGODB_URI = 'mongodb+srv://daml123:[email protected]/<dbname>?retryWrites=true&w=majority';
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
dbName: "articles",
useUnifiedTopology: true
});
mongoose.connection.on('connected', () => {
console.log('Mongoose is connected!!!!');
});
// Schema
const Schema = mongoose.Schema;
let schemaStructure = {
title: String,
authors: String,
published_date: String,
doi: String,
abstract: String,
publication_location: String,
link: String,
citations: String,
readership: String,
tweets: String,
news_mentions: String
};
const machine_learningSchema = new Schema(schemaStructure, {collection: 'machine_learning'});
// Model
const machine_learning_articles = mongoose.model('machine_learning', machine_learningSchema);
const deep_learningSchema = new Schema(schemaStructure, {collection: 'deep_learning'});
const deep_learning_articles = mongoose.model('deep_learning', deep_learningSchema);
const neural_networksSchema = new Schema(schemaStructure, {collection: 'neural_networks'});
const neural_networks_articles = mongoose.model('neural_networks', neural_networksSchema);
app.use(morgan('tiny'));
app.get('/machine_learning', (req, res) => {
machine_learning_articles.find({})
.then((data) => {
// console.log(data);
res.json(data);
})
.catch((error) => {
console.log(error);
})
})
app.get('/deep_learning', (req, res) => {
deep_learning_articles.find({})
.then((data) => {
// console.log(data);
res.json(data);
})
.catch((error) => {
console.log(error);
})
})
app.get('/neural_networks', (req, res) => {
neural_networks_articles.find({})
.then((data) => {
// console.log(data);
res.json(data);
})
.catch((error) => {
console.log(error);
})
})
app.listen(PORT, console.log(`Server is starting at ${PORT}`));