How to use the PostgreSQL droplet with NodeJS?

June 9, 2019 870 views
CentOS Node.js PostgreSQL Databases

Hello dear DigitalOcean Community,

I want to use a database for my NginX + NodeJS project that I’m working on. I surely need a SQL and a NoSQL database for my project.

1. What’s the difference between getting a ProstgreSQL droplet vs creating a droplet and installing PostgreSQL myself?
1.1 Is the PostgreSQL droplet faster compared to the “DIY PostgreSQL” droplet?

2. How do I use/connect to my PostgreSQL droplet database using NodeJS?
2.1 Which NodeJS package do I need to use for PostgreSQL?

3 Is it better to install a noSQL Database on the same droplet or on a separate one?
3.1 Will a separate droplet be faster compared to the same droplet? Much faster? One one side we have “CPU usage” and on the other side we have the delay between droplets.

1 Answer

Hi @damiantoczek,

1. This is really up to personal reference. If you don’t want to take much time on installing and configuring, I’ll recommend the first option. Having said that, I’ll recommend to check the following DO Articles - here and here. One of the articles is for Ubuntu however it’s pretty good and shows good implications.

1.1 On one hand the PostgreSQL droplet is specifically designed by DO to work with their systems. On the other, you can configure it the same way if not better for you application if you built it on your own. Having said that, I’ll again go with the first option.

2./ 2.1 You’ll need to allow connections on your PostgreSQL droplet from the droplet your applications is built on. As for the actual code and how to, I’ll recommend checking this Article

3 This really depends on the traffic you expect and the budget you have. If you expect a lot of traffic and have enough budget, it’s always better to separate your Web Service and SQL service to different load balancers.

3.1 The actual delay won’t even be noticed. If everything has been configured correctly, there will be no loss or delay to the connection. I’ll recommend going with that option!

Kind regards,
Kalin

by Mitchell Anicas
by Vadym Kalsin
PostgreSQL, or Postgres, is a relational database management system that provides an implementation of the SQL querying language. It is a popular choice for many small and large projects and has the advantage of being standards-compliant and having many advanced features like reliable transactions and concurrency without read locks. In this guide, you will install PostgreSQL on CentOS 7 and go over some basic ways to use it.
Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!