DEV Community

Cover image for Day 29 – SQL Database with Node js - Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Day 29 – SQL Database with Node js - Learning Node JS In 30 Days [Mini series]

Before coming this part of tutorial, we never talked about the database. Actually it was a basic course so I never tell anything about the database. Just wanted to make pure node js tutorial.

Today we’re going to learn how can we add a sql database with express js.

It’s pretty easy, but we need a npm package for it. Actually multiple package for it.

For the sql connection. There are some packages

  • Knex.js
  • Sqorn
  • squel
  • Objection.js and many more I personally used knex.js and objection.js. Objection actually based on knex, it has some extra benefits so I used it some projects.

Knex is good choice, beacause it has an amazing documentation. Which is pretty easy to follow.

Installing is pretty easy. As like others. But you need to install the database too. Like what you are using – mysql or postgresql or sqlite

Alt Text

Connecting is easy too, just changing the credentials will be okay.

Alt Text

You can write RAW sql with the knex too. http://knexjs.org/#Raw-Expressions

Alt Text

which one you want to use ?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

You can read the old posts from this series (below)

Oldest comments (0)