Need help with nQuery?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

449 Stars 20 Forks 76 Commits 2 Opened issues


remote control jQuery/Zepto with node.js (experimental)

Services available


Need anything else?

Contributors list

# 212,096
59 commits

nQuery (beta) -- live demo

Introducing nQuery.js, a crazy new library that lets you write jQuery on the server. And yes it works with the browser in realtime. You can bind events directly to the server, such as swipe and hover using RPC. Don't worry, it's fast.

nQuery is a minimalist DOM manipulation framework that is bringing jQuery methods to the server so you dont have to serve client side javascript in order to make a realtime cross-browser compatible 'lightweight' app.

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

The goal is to have a full DOM manipulation framework that works in realtime from the server side. If you can get away with only using jQuery in your application, this means you can completely isolate your client away from your application logic.


$ npm install nodeQuery


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

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') }) }

nQuery .use(app)

express .use(nQuery.middleware) .use(Express.static(__dirname + '/public')) .listen(3000)

dnode .use(nQuery.middleware) .listen(express)

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


Sample usage of methods on the server:

  .use(function ($) {

// 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) { 

  $('body').append('<a href="" class="link">Click me, Im a binding.</a>')

  $('').live('click', function () {
      $('').html('You clicked it!')

  $('body').append('<span class="hover">Hover me.</span>')

  $('.hover').live('mouseover', function () {
      $('.hover').html('hover event')

  // bind an event to an element which already exists in the dom
  $('.hover').bind('mouseout', function () {
      $('.hover').html('Im back again!')

  // bind an event to an element and any future elements that match the selector
  $('div').live('swipe', function () {
      $('div').html('swipe event')

  // 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 some other information about an element

  // set the html contents of the element(s)

  // set the text contents of the element(s)
  $('div').text('Hello World')

  // add html (or a DOM Element) after the element

  // add html (or a DOM Element) before the element

  // forces elements to be hidden

  // forces elements to be displayed

  // set a CSS property
  $('div').css('background-color', '#eee')

  // set an attribute
  $('div').attr('background-color', '#eee')

  // get an attribute

  // serialize a form or list of elements

  // call "nQuery.ready()" on the browser



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


Remember that just because you can update your DOM from the server doesnt mean you will always want to. A click or swipe event being bound to the server can be amazingly responsive, but if the event only changes the display of your app (i.e. color, size) then it most likely still belongs on the client to reduce the server load. There is a ready function in nQuery similar to $(document).ready() for the client as well as the server.


More Examples:

Check out the examples folder for a few simple demos.

MIT License

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.