DEV Community

Cover image for How to deploy NodeJS with PostgreSQL on AWS in 60 seconds
Romaric P.
Romaric P.

Posted on • Originally published at qovery.com

How to deploy NodeJS with PostgreSQL on AWS in 60 seconds

This article was originally published at: Qovery Blog


AWS (Amazon Web Services) is an amazing and reliable cloud service provider. AWS, like Google Cloud Platform and Microsoft Azure, provides everything you need to host an application without having to worry about running the underlying servers and network configuration. Everything you need to quickly begin hosting is provided as a packaged services.

However, deploying an application on AWS presents some challenges. The typical deployment workflow looks like this: write code, push it to Git, compile code, deploy code, validate your changes and repeat. Developers thus not only have to do all of this manually, but they also have to configure tons of services (VPC, database, cache, DNS, CDN, etc.) to make their application live on the web.

Qovery was created to solve this problem. In this blog post, I will show you how Qovery improves the developer experience to deploy staging and production NodeJS application with PostgreSQL database on AWS. You will be able to focus on writing the best code instead of managing complex services.

Prerequisites

  • Operating system: MacOS / Windows / Linux
  • A Github account

Optional: Get the NodeJS sample application

Get a local copy of the NodeJS sample project by forking the project using your Github account and by executing the following command:

⚠️ Do not forget to fork the project and change the URL below with yours

git clone -b tutorial git@github.com:YOUR_GITHUB_USERNAME/simple-example-node-with-postgresql.git
Enter fullscreen mode Exit fullscreen mode

Step 1: Install the Qovery CLI

The Qovery CLI is an open-source project that lets you deploy your applications directly on AWS, while taking advantage of well-known local tooling. We will use this tool to speed up our development cycle instead of using the typical development workflow (based on a CI/CD, Docker and other DevOps tools).

Install the Qovery CLI by running the following command:

MacOS

brew tap Qovery/qovery-cli
brew install qovery-cli
Enter fullscreen mode Exit fullscreen mode

Linux

curl -s https://get.qovery.com | bash
Enter fullscreen mode Exit fullscreen mode

Windows

scoop bucket add qovery https://github.com/Qovery/scoop-qovery-cli
scoop install qovery-cli
Enter fullscreen mode Exit fullscreen mode

Authenticate yourself before using it‍‍

qovery auth
Enter fullscreen mode Exit fullscreen mode

Step 2: Deploy the NodeJS application on AWS

To deploy the NodeJS application connected to a PostgreSQL database, you need to have a .qovery.yml file and a Dockerfile (already provided) at the root of your project. This file indicate the external resources (eg. PostgreSQL) that your application need to work properly.

Optional (but recommended): Qovery provides a Javascript client to simplify the way to retrieve the PostgreSQL instance host, port, username and password.

To create the .qovery.yml file, run the following command:‍‍

qovery init
Enter fullscreen mode Exit fullscreen mode

The .qovery.yml file is created at the root of the project directory

cat .qovery.yml
Enter fullscreen mode Exit fullscreen mode

Output

application:
  name: simple-example-node-with-postgresql
  project: simple-example-node-with-postgresql
  cloud_region: aws/eu-west-3
  publicly_accessible: true
databases:
- type: postgresql
  version: "11.5"
  name: my-postgresql-3498225
routers:
- name: main
  routes:
  - application_name: simple-example-node-with-postgresql
    paths:
    - /*
Enter fullscreen mode Exit fullscreen mode

Note: Qovery supports multiple databases (eg. PostgreSQL, MySQL, MongoDB, Redis, Memcached, Cassandra), brokers (eg. RabbitMQ, Kafka) and storage services(eg. S3).

Authorize the Qovery Github application to get access to your Github account through this link. After that, you just need to commit and push the .qovery.yml file in order to deploy your app.

git add .qovery.yml .gitignore
git commit -m “add .qovery.yml and update .gitignore”
git push -u origin tutorial
Enter fullscreen mode Exit fullscreen mode

Voila! Qovery is now deploying your app!


⚠️ BETA: During the Beta phase, the first deployment requires 26 minutes (the database requires a longer processing time while being deployed for the first time due to AWS). After that, each update will take only 2 minutes. Wait a couple of minutes and type the following command to get your application endpoint:

qovery status
Enter fullscreen mode Exit fullscreen mode

Output

Environment
branch  status  endpoints                                    applications  databases  brokers  storage
master  LIVE    https://x52d28s8iu22mwmi-main-gtw.qovery.io  1             1          0        0

Applications
name                                 status  databases  brokers  storage
simple-example-node-with-postgresql  LIVE    1          0        0

Databases
name                   status  type        version  endpoint                                                                                     port  username   password          application
my-postgresql-3498225  LIVE    POSTGRESQL  11.5     x52d28s8iu22mwmi-rq1xywcyi8wqqcmt-b5pcw97rq8456u5z.cnuxtlki1yn9.eu-west-3.rds.amazonaws.com  5432  superuser  ****************  simple-example-node-with-postgresql

Brokers
name  status  type  version  endpoint  port  username  password  application

Storage
name  status  type  version  endpoint  port  username  password  application
Enter fullscreen mode Exit fullscreen mode

Bonus 1: Test the NodeJS application locally

The Qovery motto is: if your application runs locally, then your application will run on Qovery. To test if your application is running locally, execute the following command:

Warning: Docker runtime required.

qovery run
Enter fullscreen mode Exit fullscreen mode

Output

...
Step 6/7 : EXPOSE 3000
 ---> Running in a154409a60a7
 ---> 572b7f72c640
Step 7/7 : CMD node ./bin/www
 ---> Running in e315a1fe7c35
 ---> b8c8f6b25307
Successfully built b8c8f6b25307
Enter fullscreen mode Exit fullscreen mode

Navigate to http://localhost:3000 through your web browser and you should see a Welcome message.

Note: qovery run connects your application to the PostgreSQL database on AWS.

Bonus 2: Deploy the application on a staging environment

Qovery has a very powerful feature known as “environment”. Qovery supports the deployment of isolated development environments from your branches, complete with exact copies of all of your data. This is useful for testing changes in isolation before merging them.

So, do you want to create a new feature, fix a bug or make a modification without impacting the production or any other important environment? Type the following commands:

git checkout -b feat_foo
Enter fullscreen mode Exit fullscreen mode

Do your changes if required, and commit + push them

git push -u origin feat_foo
qovery status
Enter fullscreen mode Exit fullscreen mode

Output

Environment
branch    status  endpoints                                    applications  databases  brokers  storage
feat_foo  LIVE    https://vvzwrr81194ksqaw-main-gtw.qovery.io  1             1          0        0

Applications
name                                 status  databases  brokers  storage
simple-example-node-with-postgresql  LIVE    1          0        0

Databases
name                   status  type        version  endpoint                                                                                     port  username   password          application
my-postgresql-7972832  LIVE    POSTGRESQL  11.5     vvzwrr81194ksqaw-fdhuc83ov12fayoz-kpxoosudsewqxs9b.cnuxtlki1yn9.eu-west-3.rds.amazonaws.com  5432  superuser  ****************  simple-example-node-with-postgresql

Brokers
name  status  type  version  endpoint  port  username  password  application

Storage
name  status  type  version  endpoint  port  username  password  application
Enter fullscreen mode Exit fullscreen mode

Conclusion

Qovery and AWS together bring to developers the full power of simplicity and flexibility while deploying applications. Any developer can now take advantage of AWS in seconds instead of days.

Accelerate your development and start using Qovery today. Let us know what you think about it on Twitter, or by e-mail.

Top comments (0)