If you want to skip walking through the steps, the "More information" section at the bottom has a link to a GitHub repository which can be cloned and run locally.
In this step, we'll use your terminal (e.g. Terminal, iTerm, PowerShell) to create a directory called `graphql-server-example` along with a basic Node.js configuration for a simple application. We'll work within this directory for the rest of the steps, though we will switch back and forth between your IDE (editor)
* First, create a folder called `graphql-server-example` using the `mkdir` command.
mkdir graphql-server-example
* Enter the directory, so the remaining work will take place within that directory.
cd graphql-server-example
* Initialize the new directory as a Node.js project using the Node.js package manager, `npm`.
npm init --yes
> We use `npm`, the default package manager which ships with Node.js. Other package managers, such as [Yarn](//yarnpkg.com), offer similar functionality, but will not be covered in this guide.
If the above steps all completed successfully, there should be a new `package.json` file in the directory. You can verify this by running `ls` (list files).
## Step 2: Install dependencies
Next, we'll install the two core dependencies which are necessary for responding to GraphQL requests:
* [`apollo-server`](//npm.im/apollo-server): The Apollo server library which allows you to focus on defining the shape of your data and how to fetch it.
* [`graphql`](//npm.im/graphql): The library used to build a schema and to execute queries on that schema.
> Note: There won't be any usage of the `graphql` package in this guide, but it is required to be installed separately as it's an important "peer dependency" of Apollo Server.
While you could write all of the necessary code yourself, these two dependencies make it easier to build a GraphQL server and are common in applications of all sizes.
Run the following command to install both of these dependencies and save them in the project:
npm install --save apollo-server graphql
In the next step, we'll use these dependencies to create a server which processes and responds to incoming GraphQL requests.
## Step 3: Create the server
In this step, we'll provide a code block which sets up `apollo-server` to respond to an incoming GraphQL request. In order to move along quickly, we'll have you copy and paste the code into an `index.js` file in your project. When looking at the code, we hope you'll find the comments helpful in understanding the core GraphQL concepts. Don't worry if there is something which needs more explanation; we'll point you to the right places for more details at the end of this guide.
The example code will utilize a static collection of two books. In a more complicated example, the books might be fetched from a web resource (e.g. Amazon or a local library's website) or a database (e.g. MySQL or MongoDB).
* Using the IDE/editor you've chosen (e.g. Visual Studio Code), open the `graphql-server-example` directory which we created in the first step.
> In most editors, you can open a directory by selecting the "File" menu and then "Open".
* Create a new, blank file called `index.js` in the root of the project directory.
* "Copy" the following code block, "Paste" it into the `index.js` file you created in the previous step, then "Save" the file:
The code above includes everything that is necessary to get this basic GraphQL server running. In the next step, we'll start the server so it's ready to respond to requests!
## Step 4: Start the server
For this step, we'll return to the terminal/console and start the server we defined in the previous steps.
* Run the `index.js` file we created in the previous step using Node.js
Since we're trying to obtain books, we can enter the following query on the left side of the window. This query asks for a list of books, including the title and author for each book.
This application should be a great starting point for any GraphQL server, but the following resources are a great next step in building a GraphQL server:
The code from the above examples can be accessed in our [getting started example repository](.) on GitHub, which also includes instructions on how to get started in its [readme](.).