# GraphQL Subscriptions with ExpressWS

**URL:** <https://community.apollographql.com/t/graphql-subscriptions-with-expressws/5922>\
**Category:** Server\
**Tags:** server\
**Created:** [March 12, 2023, 12:00am UTC](https://community.apollographql.com/t/graphql-subscriptions-with-expressws/5922 "2023-03-12T00:00:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdemcak](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/vdemcak/32/4028_2.png) [@vdemcak](https://community.apollographql.com/u/vdemcak)\
**Post date:** [March 12, 2023, 12:00am UTC](https://community.apollographql.com/t/graphql-subscriptions-with-expressws/5922/1 "2023-03-12T00:00:51Z")

</div>

Hello, I already have a express + express-ws server set up and I’d like to implement websockets for graphql subscriptions. The guide says that I need to create a websocket server using the ws package. Won’t that interfere with the express-ws server? This is my current main file:

```auto
/* --------------------------- External Libraries --------------------------- */
import express from "express";
import bodyParser, { json } from "body-parser";
import { ApolloServer } from "@apollo/server";
import { expressMiddleware } from "@apollo/server/express4";
import compression from "compression";
import cors from "cors";
import "reflect-metadata";
import expressWs from "express-ws";

/* ---------------------------- Internal Imports ---------------------------- */
import { DB } from "database/data-source";

/* ----------------------------- Setup Variables ---------------------------- */
const app = expressWs(express()).app;
app.use(
  cors({
    origin: "*",
  }),
  bodyParser.json(),
  compression()
);

const initiate = async () => {
  // TypeORM
  await DB.initialize();

  // GraphQL
  const gqlServer = new ApolloServer({
    typeDefs: require("./graphql/schema").default,
    resolvers: require("./graphql/resolvers").default,
  });
  await gqlServer.start();

  // Endpoints
  app.use("/v1/", require("./routes/v1/router").default);
  app.use("/graphql", expressMiddleware(gqlServer));

  // Server
  app.listen(3000, () => {
    console.log("\x1b[34mExpress \x1b[37m » API ready and listening on port 3000.");
  });
};

initiate();

```

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:49pm UTC](https://community.apollographql.com/t/graphql-subscriptions-with-expressws/5922/2 "2025-02-06T20:49:20Z")

</div>


