v2
Integrations
Express
⚠️
This is the documentation for the old GraphQL Yoga version 2. We recommend upgrading to the latest GraphQL Yoga version 5.

Migrate to GraphQL Yoga v5

Integration with Express

Express is the most popular web framework for Node.js. It is a minimalist framework that provides a robust set of features to handle HTTP on Node.js applications. You can easily integrate GraphQL Yoga into your Express application with a few lines of code.

Installation

Terminal
yarn add @graphql-yoga/node express graphql

Example

import express from 'express'
import { createServer } from '@graphql-yoga/node'
 
const app = express()
 
const graphQLServer = createServer()
 
// Bind GraphQL Yoga to `/graphql` endpoint
app.use('/graphql', graphQLServer)
 
app.listen(4000, () => {
  console.log('Running a GraphQL API server at http://localhost:4000/graphql')
})
💡

You can also check a full example on our GitHub repository here.