# Using MassiveJS with Node and Postgres for database queries

DevFeed: [Using MassiveJS with Node and Postgres for database queries](<https://devfeed.tech/articles/node-postgres-massivejs-a-better-database-experience-41181.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2015/11/30/Node-Postgres-MassiveJS-A-better-database-experience/>)

Author: Map

Published: 2015-11-30T20:55:56Z

Content type: article

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

Topics: [Databases](<https://devfeed.tech/topics/databases.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>), [App](<https://devfeed.tech/topics/app.md>)

Tags: [crud](<https://devfeed.tech/tags/crud.md>), [database](<https://devfeed.tech/tags/database.md>), [install](<https://devfeed.tech/tags/install.md>), [localhost](<https://devfeed.tech/tags/localhost.md>), [node](<https://devfeed.tech/tags/node.md>), [npm](<https://devfeed.tech/tags/npm.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

This tutorial evaluates MassiveJS as an alternative to conventional ORMs for Node applications using Postgres. It demonstrates connecting to a database, querying users, requiring a primary-key index, and running arbitrary SQL.

## Source excerpt

First some background-I've always had a bit of a love hate relationship with ORMs. ORMs are great for basic crud applications, which inevitably happens at some point for an app. The main two problems I have with ORMs is: They treat all databases as equal (yes, this is a little overgeneralized but typically true). They claim to do this for database portability, but in reality an app still can't just up and move from one to another. They don't handle complex queries well at all. As someone that sees SQL as a very powerful language, taking away all the power just leaves me with pain. Of course these aren't the only issues with them, just the two ones I personally run into over and over. In some playing with Node I was optimistic to explore Massive.JS as it seems to buck the trend of just imitating all other ORMs. My initial results-it makes me want to do more with Node just for this library. After all the power of a language is the ecosystem of libraries around it, not just the core language. So let's take a quick tour through with a few highlights of what makes it really great. Getting setup Without further adieu here's a quick tour around it. First let's pull down the example database from PostgresGuide Then let's setup out Node app: $ npm init $ npm install massive --save Connecting and querying Now let's try to connect and say query a user from within our database. Create the following as an index.js file, then run with node index.js: var massive = require("massive"); var connectionString = "postgres://ckerstiens:@localhost/example"; var db = massive.connectSync({connectionString : connectionString}); db.users.find(1, function(err,res){ console.log(res); }); Upon first run if you're like me and use the PostgresGuide example database (which I now need to go back and tidy up), you'll get the following: db.users.find(1, function(err,res){ ^ TypeError: Cannot read property 'find' of undefined I can't describe how awesome it is to see this. What's happening is when Mass