Server that interfaces with SpaceX API to allow users to book seats on the next SpaceX launch
A couple of things you need to have on your local development environment include:
You need to ensure you have Docker & Docker Compose installed on your local development environment, as they are used when running containers. More explanation on containers can be found in the links provided for Docker and docker-compose
You require a working version of NodeJS as this is a Node based application and npm or yarn for package management. Yarn has been preferred for this application, but npm can be used as well
Getting started is quite straighforward and the following steps should get you up and running.
$ git clone https://github.com/Wyvarn/space-xplorer-server.git
$ cd space-xplorer-server
$ yarn install
# if using npm
$ npm install
This will install the required dependencies
This uses a PostgreSQL DB as a persistence provider. Thus, for local development, you will need a running instance of this DB. This is provided with Docker for local development.
To get this DB up & running. First set the environment variables that you will need when running it:
cp .env.example .env
cd prisma
cp .env.example .env
Prefill the .env
file created with the relevant details for the environment variables you will use in the project.
Now you can start up the DB as below:
docker-compose up
This will start up the DB
Now you can perform migrations as below:
yarn migrate:up
This will run migrations as specified in the migrations folder
To create a new migration, simply change the schema in the schema and then run a migration with:
yarn migrate:create
yarn migrate:up
NOTE: These commands are interchangebale with NPM(npm)
Now you are all set to run the application:
yarn start
That should pretty much be it when running the application. You can now navigate to http://localhost:4000 on your browser & should be able to view the GraphQL client browser & create queries.
This application has been built for it to be deployed on any environment:
- As a vanilla deployment as a server with a process manager or with Node
- Running in a Docker container in an environment that supports Docker runtime
- In a Kubernetes cluster inside a Pod
All the configurations have been put in place for this application to run in a predictable manner.
Only a few things you will need to do:
-
Set environment variables in your environment as specified in the .env.example
-
Ensure that DB migrations are run before application start
- If running in a vanilla Node JS environment, you can use the npm scripts provided to run migrations
- If running in a Docker runtime supported environment, you can use the Dockerfile.migrations file to build an image specifically for running DB migrations. This will run & exist successfully
- If running in a Kubernetes supported environment using Deployments, the templates specified in the k8s folder will give a hint on how to enable these migrations to run before application start using init containers
And that should be it to get you a working running API with GraphQL.