Getting started with Node.js and Express.js
One of the primary goals of this book is to set up a GraphQL API, which is then consumed by our React frontend. To accept network requests – especially GraphQL requests – we are going to set up a Node.js web server.
The most significant competitors in the Node.js web server area are Express.js, Koa, and Hapi. In this book, we are going to use Express.js. Most tutorials and articles about Apollo rely on it.
Express.js is also the most used Node.js web server out there and describes itself as a Node.js web framework, offering all the main features needed to build web applications.
Installing Express.js is easy. We can use npm
in the same way as we did in the previous chapter:
npm install --save express
This command adds the latest version of Express to package.json
.
In the previous chapter, we created all the JavaScript files directly in the src/client
folder. Now, let's create a separate folder for our...