The simplest way to run an GraphQL API server is to use Express, a popular web application framework for Node.js.

Introduction

Here I am going to show you how to setup GraphQL server and run it from a Linux hosting server. Connect your Linux server using SSH Shell command. As I am using an A2Hosting server, I am going to use this SSH command in my terminal windows.

Prerequisites

Before starting, make sure you have Node.JS and NPM is installed on your server environment. If you haven’t installed on your server, you check below link as well.

Once you haveNode.JSandNPMinstalled on your server, let’s get started with SSH command in your terminal. Keep your SSH credentials in hand. Open your terminal window and type this command.

In order to handleGraphQLqueries, we need to first create a schema that has a Query type, and we need an API root with a function called a resolver for each API endpoint. So, create this server file and deploy it on your server folder using either an FTP tool or cPanel window.

Run Your GraphQL Server

Now, once you deploy your server file on the server, run this command on your server using ssh command.

node graphserver.js

It will show this console message.

Running a GraphQL API server at serverurl/graphql

Now, we are all set. It is time to test our GraphQL server. Run your server service url in the browser like this:

Fire Query

Now, our GraphQL server is up, let’s query our data using this command in the left side of the window, and click on the Run arrow button.