-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (23 loc) · 786 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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const graphqlHTTP = require("express-graphql");
const schema = require("./schemas/schemas");
const mongoose = require("mongoose");
//Connecting to the database
mongoose.connect(process.env.MONGO_DATABASE_URI,()=>{
console.log("Connected to the database successfully !!!");
})
//Creating the app using express
const app = express();
//Using cors for giving access to the front-end client server
app.use(cors());
//Using the express-graphql as a middleware
app.use("/graphql",graphqlHTTP.graphqlHTTP({
schema,
graphiql: true
}));
//Starting the express server on port 4000
app.listen(process.env.PORT | 4000,()=>{
console.log("Backend server started on port 4000");
});