-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
31 lines (23 loc) · 831 Bytes
/
app.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
const express = require('express')
const mongoose = require('mongoose')
const TextBlob = require('./models/Text')
const app = new express()
if (process.env.NODE_ENV === 'development') {
mongoose.connect('mongodb://localhost/my_database', {useNewUrlParser: true})
}
if (process.env.NODE_ENV === 'production') {
mongoose.connect("mongodb+srv://typing_app_user1:YCeiNNbmePqJLjZz@typinggame.fxpm7.mongodb.net/test", {useNewUrlParser: true});
}
app.use(express.static('static'))
//Queries the database with a random id and responds with a text
app.get('/text', async(req, res) => {
let textBlob = await TextBlob.findOne({"id" : 1});
res.send(textBlob.text)
})
let port = process.env.PORT
if (port == null || port === ""){
port = 4000
}
app.listen(port, ()=>{
console.log('App listening on port 4000')
})