Before we dive into building API servers, you need to understand how to use one.
Splitting up the client and server
When we have an API server, we generally split up the client and server into two projects
This conforms to Rest Principle #1 (Client-Server) and allows us to evolve the client project and server project separately.
Running two servers simultaneously
When you have this architecture, you need to run two servers simultaneously.
- One to serve the client
- One to serve the API
Because of this, it’s common to see two terminal windows opened on a developer’s computer at the same time.
Serving the client
The easiest way to serve the client is to use a library called http-server.
You can install http-server with this:
npm install http-server -gOnce it is installed, you can run http-server in the client and you should be able to access the page at http://locahost:8080
You can also serve the client with Node as well — this will fall under the realm of a traditional server and is out of the scope of this course.
Running the API Server
Running the API server is simple: all you have to do is use node or nodemon like what you’ve learned so far:
nodemon server.js
With this, you’re ready to proceed to the next lesson.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson