-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 710 Bytes
/
Copy pathserver.js
File metadata and controls
33 lines (28 loc) · 710 Bytes
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
const { ApolloServer } = require("apollo-server");
const { typeDefs, resolvers } = require("./graphql/schema");
const mongoose = require("mongoose");
const url = require("./mongoose/connectionConfig");
mongoose.connect(url);
const db = mongoose.connection;
const server = new ApolloServer({ typeDefs, resolvers, cors: true });
server.listen().then(({ url }) => {
console.log(`
[SERVER] GraphQL started at ${url}
[SERVER] Waiting for MongoDB connection...
`);
});
db.on('error', () =>
console.log(
`
[ERROR] Failed to establish connection to MongoDB.
`
)
);
db.once('open', () =>
console.log(
`
[SERVER] Connected to MongoDB
[SERVER] Everything up and running!
`
)
);