node package manager


nQuery (beta)

nQuery lets you use $() on the server to manipulate the browser side in realtime. It accomplishes this using, Dnode, Browserify, and either jquery or Zepto.

nQuery is a minimalist DOM manipulation framework, it's fast, and its bringing all of the jquery methods to the server so you dont have to write (or serve!) any client side javascript in order to make a realtime browser application.

The current API matches both jquery and zepto counterparts, so you can include either one on the client side.

The goal is to have a full DOM manipulation framework that works in realtime from the server side. This means you are mostly just setting attributes, html, values and binding events in jquery just like you would normally, but these methods work seamlessly with the server side of your code.


$ npm install nodeQuery


Create a file to serve up jquery and nquery and put it in /public

<!doctype html>
<script type='text/javascript' src='/jquery.js' charset='utf-8'></script> 
<script type='text/javascript' src='/nquery.js' charset='utf-8'></script>

Create an app.js file

var Express = require('express')
    , dnode = require('dnode')()
    , nQuery = require('../')
    , express = Express.createServer();
var app = function ($) {
    $.on('ready', function () {
        $('body').append('Hello World');
  .use(Express.static(__dirname + '/public'))

Visit the html file you created to see "Hello World"


Remember that just because you can write jquery on the serer doesnt mean you will always want to. A click event being bound to the server for a form is amazingly powerful, but if your mouseover or swipe event only changes the display features of your app (i.e. color, size) then it most likely still belongs on the client to reduce the server load. There is a method in nQuery.js similar to $(document).ready() for the client as well as the server. On the client it is nQuery.ready()

<!doctype html>
<script type='text/javascript' src='/jquery.js' charset='utf-8'></script> 
<script type='text/javascript' src='/nquery.js' charset='utf-8'></script>
<script type='text/javascript'>
nQuery.ready(function(options) {
    // optionally get something from the server with ready(options) 
    // do something once the server has fired "ready()" 
    // ... 


So far only a limited number of jquery/zepto methods are available, but these include some of the most powerful functionality in jquery. You may create live bindings to events and you can use all of the event types that are available with jquery or zepto to do this, including:

swipe swipeLeft swipeRight swipeUp swipeDown doubleTap tap longTap focusin focusout load     resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout change     select keydown keypress keyup error

Sample usage of methods on the server:

nQuery.use(function ($, connection) {
  // similar to '$(document).ready()', this function 
  // is called after the client DOM is ready, a callback is passed 
  // aswell, which calls 'nQuery.ready()' on the browser 
  $.on('ready', function (callback) { 
    $('.container').append('<a href="#/click" class="clickable">Click me, Im a binding.</a>');
    $('.clickable').live('click', function () {
        $('.clickable').html('You clicked it!');
        $('.clickable').attr('href', console.log);
    $('.container').append('<span class="hoverable">Hover me.</span>');
    $('.hoverable').live('mouseover', function () {
        $('.hoverable').html('hover event');
    // bind an event to an element and any future elements that match the selector 
    $('.title').live('swipe', function () {
        $('.title').html('swipe event');
    // bind an event to an element which already exists in the dom 
    $('.hoverable').bind('mouseout', function () {
        $('.hoverable').html('Im back again!');
    // unbind an event 
    $('.hoverable').unbind('mouseout', function () {
        $('.hoverable').html('Im back again!');
    // get the name of the selector (useful to determine if html element exists) 
    // get the number of elements 
    // get the index of the element 
    // set the html contents of the element(s) 
    $('body').html('<div class="app"></div>');
    // set the text contents of the element(s) 
    $('.app').text('Hello World');
    // add html (or a DOM Element) after the element 
    // add html (or a DOM Element) before the element 
    // add html (or a DOM Element) at the beginning of the element contents 
    // add html (or a DOM Element) at the end of the element contents 
    $('.container').append('is the current time');
    // reverse of append 
    // reverse prepend 
    // replace element with html 
    // forces elements to be hidden 
    // forces elements to be displayed 
    // set a CSS property 
    $('.clock').css('background-color', '#eee');
    // set an attribute 
    $('.clock').attr('background-color', '#eee');
    // get an attribute 
    // serialize a form or list of elements 
    // call "nQuery.ready()" on the browser 

More Examples:

Check out the todos app written with tubes and nquery

Check out the examples folder for a few very simple demos. There are two different clocks that run based on the server time, a twitter search app that implements backbone conventions and a simple hello world app.

MIT License