If you’re developing web applications, you’re almost certainly going to be constantly interacting with a database. And when it comes time to select the _way _you’ll interact, the choices can be overwhelming.
In this article, we’re going to look in detail at 5 different ways to interact with your database using JavaScript, and we’ll talk about the pros and cons of each. We’ll start with the lowest-level choice — SQL Commands — then move through to higher-level abstractions.
Choosing the right database library for your JavaScript application can have a big impact on the maintainability, scalability, and performance of your code, so it’s worth spending some time to figure out your options.
We’re going to use a trivial Express application hosted on Heroku as our example. All the code for this article is in this GitHub repository. Feel free to clone it and follow along.
To run the sample application, you’ll need the following software on your machine:
If you don’t have a Heroku account already, you’ll need to sign up for a free account. If you don’t want to sign up for Heroku, you can also run the application locally against a local Postgres instance. If you’re comfortable with that, it should be pretty easy to see what changes you need to make instead of deploying to Heroku.
Once you’ve installed all the above, run heroku login
in a terminal, and you’re ready to get started.
Build and Deploy the Hello World App
To start, we’ll set up the following:
#javascript #database #heroku #sql #mysql