Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda