The JavaScript blog.


libraries node modules postgres npm phantom

Node Roundup: Nightmare, Prototypes, node-libpq and node-pg-native

Posted on .



By far the most brittle and confusing part of testing is full stack integration testing. I've used lots of different approaches, whether they're based on PhantomJS or Selenium, but they always cause me trouble.

One issue is often the API -- PhantomJS itself has a strange API if you're more used to Node development. That's why I was excited to hear about Nightmare (GitHub: segmentio / nightmare, License: MIT, npm: nightmare), which aims to simplify Phantom's API.

If you want to try it out be aware that you'll need to install PhantomJS on your system. This can be done using Homebrew on a Mac, and there are packages for other platforms on the main site.

Nightmare has a chainable API that allows you to evaluate JavaScript on the target page's DOM. If you've got a page with jQuery on it, for example, then you can access $ in the evaluate callback.

Here I've loaded a web app that starts a server (in app.js), then filled out a sign in form and submitted it. The code in the evaluate method will be executed on the page, so I can use jQuery to do DOM stuff.

var server = require('./app');  
var Nightmare = require('nightmare');  
new Nightmare()  
  .type('input[name="email"]', 'alex@example.com')
  .type('input[name="password"]', 'password')
  .evaluate(function() {
    return $('.sign-out').is(':visible');
  }, function(visible) {
    assert(visible, '.sign-out should be visible');
  .run(function() {

Naturally you can use this for the general chores you'd use Phantom for, but I think it might be quite cool for testing projects with complex client-side code.


Alex Fernández sent in prototypes (GitHub: alexfernandez / prototypes, License: MIT, npm: prototypes). This module modifies prototype objects, so use it with caution, but you might find some of the methods useful.

Here are some examples:

'hi.there'.substringFrom('.'); // 'there'

{ a: 1, b: 2 }.forEach(function(value, key) {
  console.log(key, value);

node-libpq and node-pg-native

node-libpq (GitHub: brianc / node-libpq, License: MIT, npm: libpq) by Brian M. Carlson is a set of native bindings to the PostgreSQL libpq C client library.

This module attempts to mirror as closely as possible the C API provided by libpq and provides the absolute minimum level of abstraction. It is intended to be extremely low level and allow you the same access as you would have to libpq directly from C, except in node.js! The obvious trade-off for being "close to the metal" is having to use a very "c style" API in JavaScript.

Brian is the author of the popular pg PostgreSQL library, and has also recently released node-pg-native. node-pg-native is a high performance PostgreSQL module that uses node-libpq.

Sean Levy sent in node-pg-native because he's excited about the synchronous API:

var rows = client.querySync('SELECT NOW() AS the_date')  
console.log(rows[0].the_date) //Tue Sep 16 2014 23:42:39 GMT-0400 (EDT)  

It's really that simple!


server node database postgres mail time

Node Roundup

Posted on .

Welcome to the Node Roundup. Send in your apps and libraries using our
contact form or @dailyjs.


Non-blocking (async) JavaScript PostgreSQL client for node.js written fully TDD and with lots of love.

node-postgres is a non-blocking PostgreSQL client library
released under the MIT license by Brian Carlson.

Carlson has been working hard to have high test coverage, and he's
running his tests on Ubuntu and Mac OS. He's currently working hard to
get the wiki documentation up to speed, as well as date coercion working
correctly. The library currently supports prepared statements, query
caching, and notification messages.

Usage currently looks like this:

var Client = require('node-postgres').Client;
var client = new Client({
  user:     'user',
  database: 'test',
  password: 'pass'  //plaintext or md5 supported


var printRow = function(row) {

var simpleQuery = client.query("select * from user where heart = 'big'");
simpleQuery.on('row', printRow);


node-zoneinfo by Andrew Johnston is a library for dealing with tz
files. These databaes
are used to determine time zone with UTC offsets and daylight saving.

The author is attempting to convert between different timezones using
this library, so if you're doing something similar it might be worth
checking out.

A similar library is timezone-js
by Matthew Eernisse. He gives examples with Rhino (I haven't tried it
with Node).


mailparser (BSD license) by Andris Reinman is an asynchronous and non-blocking parser for node.js to
parse mime encoded e-mail messages. It can handle large attachments by
parsing them in chunks. A bit of mime email knowledge is required to use
the library, but the project has a nice little
README with enough examples to get started.

Full Text Search in 1k

Karussell has released jsii, a full
text search library. It's in-memory, runs as a HTTP server, and is even
compatible with Solr. He's written more in a blog post: jsii – full
text search in 1K LOC of