DEV Community

Romaric P.
Romaric P.

Posted on • Updated on

3 steps to deploy your NodeJS app and PostgreSQL with Github

All developers are not equal, some know how to deploy their applications, others don’t. But now it’s over! With Qovery, all developers can deploy their application in the Cloud in just a few seconds.

Qovery integrates seamlessly with Github and requires no effort from the developer.

We know how it can be painful for developers to deploy applications, manage staging/development/features environments, synchronize databases and all system stuff - even in the Cloud.

Developers should spend time doing what they love - developing applications, instead of wasting time on configuring databases, CDN, cache, network... That's why we decided to create Qovery. The first Container as a Service platform that allows any developer (junior, senior, backend, frontend...) to deploy applications in just a few minutes.

In this article, I show you how to deploy your NodeJS app with PostgreSQL from your Github and get a public URL. Let's go!

Before you begin, this tutorial assumes:

  • You have a Github account
  • You have a NodeJS app

1. Install the Qovery Github app

Click here to install the Qovery Github app.

Qovery watch your repository change to build and deploy your NodeJS app automatically. Obviously, you can limit access permissions to the repositories you want to deploy.

2. Add files to deploy your app

At the root of your project you must add 3 files to deploy your app.

  • Dockerfile: to build and run your app.
  • .qovery.yml: to indicate to Qovery that you need a PostgreSQL database for your app.
  • .env: to link your app to the provided PostgreSQL database.

Dockerfile

You can skip this step if you already have a Dockerfile at the root of your repository. Otherwise add the one below.

FROM node:13-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . .
RUN npm install

EXPOSE 3000
CMD node ./bin/www
Enter fullscreen mode Exit fullscreen mode

!!! YOU MAY NEED TO ADAPT THIS DOCKERFILE DEPENDING OF YOUR APP !!! Write down a comment if it does not work for you. I'll help.

.env

To link your NodeJS app to your database, you have to add this .env at the root of your repository as well.

DATABASE_URL=$QOVERY_DATABASE_MY_PSQL_CONNECTION_URI
Enter fullscreen mode Exit fullscreen mode

Then you can use the DATABASE_URL env variable in your code to get access to your database.

.qovery.yml

To deploy your NodeJS app you need to add this file which indicates that you required a PostgreSQL database. (It's also possible to have MongoDB, Redis, and MySQL. Take a look here)

application:
  name: my-node-app
  project: my-first-project
  publicly_accessible: true
databases:
- type: postgresql
  version: "12"
  name: my-psql
routers:
- name: my-router
  routes:
  - application_name: my-node-app
    paths:
    - /
Enter fullscreen mode Exit fullscreen mode

A deployment of your app is triggered when the Dockerfile and the .qovery.yml are added.

Congrats, your app is deployed! 🎉

3. Get your app URL

Github provides status info for each commit. Hooah! You get your public URL and your app is accessible through the auto generated URL 😎

See the screenshot, and click on the commit status to get your URL.

Github get public URL

You have access to the deployment info in real time.

In details

Demo

Check out this demo project: https://github.com/Qovery/simple-example-node-with-postgresql

Get the public URL from Github: https://github.com/Qovery/simple-example-node-with-postgresql/runs/1510964869

Public URL: https://main-oh1rtlp3q1iv59sf-gtw.qovery.io/

Conclusion

You can now deploy your NodeJS app (and any other) with PostgreSQL from Github. There is no magic, my team and I are working on Qovery for one year. And we are backed by the co-founders of Docker, Datadog, Contentsquare and much more...

Note:

  • You can deploy your app from public and private Github repositories
  • Each branch has an unique environment and URL.
  • It's 100% free for individual developers.

What do you think? Show me your deployed apps in comment below 👇 Give +1 if you liked this post 🙏

Top comments (0)