Node.js server with Apollo GraphQL and Postgres.
Requirements:
- Docker
- Free port for server listening
With Docker installed, type this command in your terminal.
docker run -ti -d --privileged=true -p PORTNUMBER:3001 --name CONTAINERNAME carloschfa/related-code-messenger-server-postgres:1.0.0 "sbin/init"
Where PORTNUMBER is the free port for your server where your application will connect and CONTAINERNAME is the name of your container, just for a better organization, we dont want to remove the wrong container in the future, right?
In my case the command will be this way:
docker run -ti -d --privileged=true -p 3123:3001 --name messenger-server carloschfa/related-code-messenger-server-postgres:1.0.0 "sbin/init"
I'm mapping my Port number to be the 3123 and the container name to be messenger-server. After you run the command, your output should be something like this:
Unable to find image 'carloschfa/related-code-messenger-server-postgres:1.0.0' locally
1.0.0: Pulling from carloschfa/related-code-messenger-server-postgres
8a29a15cefae: Pull complete
9b8c91efdfb3: Pull complete
e99cc0f436ce: Pull complete
Digest: sha256:fa56ec0195bf830920d6079be92f1f1de14c40f7ae1492b3197b46c7373c9ce8
Status: Downloaded newer image for carloschfa/related-code-messenger-server-postgres:1.0.0
a80a8014cbd1717c173467846ff033f01c66674c5f323c4440fa5ba39d47e201
You can type in your browser the following URL to check if everything works as expected: localhost:PORTNUMBER in my case localhost:3123
Login in you AWS Console, choose an appropriate region for your server and follow the video instructions.
Login in you DigitalOcean Account and follow the video instructions.
If after you running the container you receive a Connection refused
error when doing any query in GraphQL, do the following commands:
docker stop CONTAINERNAME
service docker stop
service docker start
docker start CONTAINERNAME
And check if it works.
This server uses a number of open source projects to work properly:
- Node.js - evented I/O for the backend
- Apollo GraphQL - GraphQL server.
- PG - Postgres connector.
- Sequelize - Database ORM.
- ESM - Babel-less module loader.