Node News: Node 0.11.14, svgexport, node-webkitgtk, Nightmare, Prototypes, node-libpq and node-pg-native
- Transfer
Node 11.11.14
I saw the light of the Node 0.11.14 , carrying in itself an update for
uv
, http_parser
, npm
, openssl
, and v8
. It seems that this update contains corrections for almost all modules:
cluster
rolled back to version 0.10 (behavior setupMaster
), console.dir
accepts options, events are able to output / return other events that have the ability to proceed (event that is leaking). In short, we have many changes that you need to know about before upgrading. The version
uv
included in 11.11.14 is rc1. In addition, when I visited the repository uv
to check the latest commits, I noticed a cool logo with unicornorex (unicorn dinosaur).svgexport
svgexport (GitHub: shakiba / svgexport , npm: svgexport ) by Ali Shakiba is a command line utility for converting SVG files to PNG, JPEG, and PDF.
The utility is based on
PhantomJS
and the author used it to automatically convert icons for iOS and Android projects. This is similar to the cool use of Node / Gulp / Grunt as part of a non-web native assembly chain, which I had not previously suspected.node-webkitgtk
node-webkitgtk (GitHub: kapouer / node-webkitgtk , License: MIT , npm: webkitgtk ) by Jérémy Lal is a collection of webkitgtk bindings for Node. The product’s programming interface can be called up in a chain, so you can do something like this:
WebKit().load('http://github.com').png('github.png').pdf('github.pdf')
This product was created for use without troubles, so it can be useful for such things as generating website thumbnails or for integration testing, but I have not tried to use it.
Nightmare
By far, the most fragile and confusing part of testing is full stack integration testing. I used a bunch of different approaches based either on
PhantomJS
or on Selenium
, but all of them always caused difficulties. One of the common problems lies in the interaction interfaces (APIs) -
PhantomJS
it itself has a strange API, especially if you are used to the standard development of Node applications. That is why I was delighted to hear about Nightmare (GitHub: segmentio / nightmare , license: MIT , npm: nightmare ), whose goal is to simplify the program interface for interacting with PhantomJS
. If you want to try
Nightmare
in action, be careful, you will need to install PhantomJS
on your system. This can be done using Homebrew
on poppies, but here (on the main project site) you can find packages for other platforms. Nightmare
has a chainable programming interface (API) that allows you to run JavaScript on the DOM on the target page. If, for example, you have a page loaded jQuery
, then you can access the $
function evaluate
during the callback. Here I downloaded a web application that starts the server (s
app.js
), then I filled out the input form and sent it to the server. The code in the function evaluate
will be executed on the page, so that I can use it jQuery
to work with the DOM.var server = require('./app');
var Nightmare = require('nightmare');
new Nightmare()
.goto('http://localhost:3000')
.type('input[name="email"]', 'alex@example.com')
.type('input[name="password"]', 'password')
.click('.sign-in')
.evaluate(function() {
return $('.sign-out').is(':visible');
}, function(visible) {
assert(visible, '.sign-out should be visible');
})
.run(function() {
server.close();
});
Naturally, you can use this product for general tasks for which you would use
PhantomJS
, but it seems to me that it could be quite cool to use Nightmare
for testing complex code on the client side.Prototypes
Alex Fernández introduced to our attention prototypes (GitHub: alexfernandez / prototypes , licensed: MIT , npm: prototypes ). This module modifies prototype objects, so use it carefully, but you can also find some useful methods.
Here is a usage example:
'pepitus'.startsWith('pep');
'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 ) from Brian M. Carlson is a collection of native libpq bindings of the client C library for PostgreSQL.
The task of this module is to reflect as close as possible the C programming interface presentedlibpq
and provide an absolutely minimal level of abstraction. This product is intended to be extremely low-level and give the user the same access to libpq that can be obtained directly from C, with the exception of node.js! Since you have to pay for everything, the fee for "proximity to hardware" is the need to use a programming interface similar to C in style in JavaScript.
Brian is the author of the popular pg
PostgreSQL
library , and he also recently released node-pg-native , which is a high-performance module using .
Sean Levy introduced us to node-pg-native because he is crazy about the synchronous software interface:PostgreSQL
node-libpq
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!
From translator
Here is a translation of two articles by Alex
For some time I decided to go into the field of open source software development, so if anyone wants to take the baton of the translation of reviews from Alex, I and probably the community as a whole will be happy to see these translations.
Thank you all for your attention.