Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Not able to figure out why my server is not running
import express, { Application, Request, Response, NextFunction } from "express";

import connectToDB, { getMongoClient } from "./utils/db";
import dotenv from "dotenv";
import {ApolloServer} from 'apollo-server-express'
import {typeDefs} from './schemas/todo'
import UserData, {UserDocument} from './datasources/userdatasource'
import {UserResolver} from './resolvers/userResolver'
import { Collection } from "mongodb";
import {buildSchema} from 'type-graphql'
import {customAuthChecker} from './auth/authChecker'
import { validateAcessToken } from "./middleware/checkToken";
import http from 'http'

dotenv.config();



const app: Application = express();
const path:string = "/graphql";
const httpServer = http.createServer(app);
// let userCollection:Collection<UserDocument>;
(async () => {
  try {
    await connectToDB();
    console.log("Database connected Welcome")
  } catch (error) {
    console.log(error)
  } 
})();

async function startServer(){
  try {
    const schema = await buildSchema({
      resolvers:[UserResolver],
      dateScalarMode: "isoDate",
      authChecker:customAuthChecker,
    })
  
    const server = new ApolloServer({schema,
    context: ({req, res}) => {
      return {req, res}
    }
    
    })
    app.use(validateAcessToken)
    await server.start()
    server.applyMiddleware({app, path})

    await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
  console.log(`๐Ÿš€ Server ready at http://localhost:4000${server.graphqlPath}`);
  
    
  } catch (error:any) {
    console.log(error.message)
  }
}

startServer()

I am writing the above code to get my apollo-server-express to startup. I even get the message that my server has started in the terminal but when I navigate to the url the server is not running any idea why this might be the case. Will be helpful if someone could help me out

about 4 years ago ยท Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!