-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 909 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 909 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
require('dotenv').config();
const express = require('express');
const {ApolloServer}= require('apollo-server-express');
const typeDefs = require('./graphql/schema');
const resolvers = require('./graphql/resolvers');
const {pool} = require('./db/db');
const app = express();
const Server = new ApolloServer({typeDefs,resolvers});
async function startServer() {
await Server.start();
Server.applyMiddleware({ app });
}
startServer().then(() => {
const port = process.env.port || 3000;
app.listen(port, async () => {
console.log(`Server running at http://localhost:${port}${Server.graphqlPath}`);
// Test database connection
try {
const Pool = pool.promise();
await Pool.query('SELECT 1');
console.log('Database connected');
} catch (error) {
console.error('Database connection error:', error.message);
}
});
});