-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (24 loc) · 752 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 graphqlHTTP = require('express-graphql');
const mongoose = require('mongoose');
const schema = require('./api/graphql');
const app = express();
const startServer = async () => {
try {
const mongoDB = 'mongodb://database/commu-list';
await mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
console.log('database connected');
} catch (err) {
console.log(err);
}
app.get('/', (req, res) => {
res.json({ name: 'http://localhost:8080/graphql' });
});
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}));
app.listen(8080, () => console.log('now listennig for requests on port 8080'));
};
startServer();
module.exports = app;