-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (19 loc) · 791 Bytes
/
index.js
File metadata and controls
24 lines (19 loc) · 791 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
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const schema = require('./schema');
const resolvers = require('resolvers');
const dotenv= require('dotenv');
const connectDB = require('./db'); // Import your database connection
dotenv.config();
const app = express();
const startServer = async () => {
await connectDB(); // Connect to MongoDB before starting the server
const server = new ApolloServer({ typeDefs: schema, resolvers });
server.applyMiddleware({ app });
// Port definition and server logs
const port = process.env.PORT || 4000; // Use environment variable for port or default to 4000
app.listen(port, () =>
console.log(`Server ready at http://localhost:${port}${server.graphqlPath}`)
);
};
startServer();