Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 716977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:21:36+00:00 2026-05-14T05:21:36+00:00

Does anyone know off a way or maybe think its possible to connect Node.js

  • 0

Does anyone know off a way or maybe think its possible to connect Node.js with Nginx http push module to maintain a persistent connection between client and browser.

I am new to comet so just don’t understand the publishing etc maybe someone can help me with this.

What i have set up so far is the following. I downloaded the jQuery.comet plugin and set up the following basic code:

Client JavaScript

<script type="text/javascript">

    function updateFeed(data) {
        $('#time').text(data);
    }

    function catchAll(data, type) {
        console.log(data);
        console.log(type);
    }

    $.comet.connect('/broadcast/sub?channel=getIt');
    $.comet.bind(updateFeed, 'feed');
    $.comet.bind(catchAll);

    $('#kill-button').click(function() {
        $.comet.unbind(updateFeed, 'feed');
    });
</script>

What I can understand from this is that the client will keep on listening to the url followed by /broadcast/sub=getIt. When there is a message it will fire updateFeed.

Pretty basic and understandable IMO.

Nginx http push module config

default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
push_authorized_channels_only off;

server {
  listen       80;
  location /broadcast {
    location = /broadcast/sub {
      set $push_channel_id $arg_channel;
      push_subscriber;
      push_subscriber_concurrency broadcast;
      push_channel_group broadcast;
    }

    location = /broadcast/pub {
      set $push_channel_id $arg_channel;
      push_publisher;
      push_min_message_buffer_length 5;
      push_max_message_buffer_length 20;
      push_message_timeout 5s;
      push_channel_group broadcast;
    }
  }
}

Ok now this tells nginx to listen at port 80 for any calls to /broadcast/sub and it will give back any responses sent to /broadcast/pub.

Pretty basic also. This part is not so hard to understand, and is well documented over the internet. Most of the time there is a ruby or a php file behind this that does the broadcasting.

My idea is to have node.js broadcasting /broadcast/pub. I think this will let me have persistent streaming data from the server to the client without breaking the connection. I tried the long-polling approach with looping the request but I think this will be more efficient.

Or is this not going to work.

Node.js file

Now to create the Node.js i’m lost. First off all I don’t know how to have node.js to work in this way.

The setup I used for long polling is as follows:

var sys = require('sys'), 
http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(new Date());
    res.close();
    seTimeout('',1000);
}).listen(8000);

This listens to port 8000 and just writes on the response variable.

For long polling my nginx.config looked something like this:

server {
  listen      80;
  server_name _;

  location / {
    proxy_pass   http://mydomain.com:8080$request_uri;
    include      /etc/nginx/proxy.conf;
  }
 }

This just redirected the port 80 to 8000 and this worked fine.

Does anyone have an idea on how to have Node.js act in a way Comet understands it. Would be really nice and you will help me out a lot.

Recources

used

  • An example where this is done with ruby instead of Node.js
  • jQuery.comet
  • Nginx HTTP push module homepage
  • Faye: a Comet client and server for Node.js and Rack

To use faye I have to install the comet client, but I want to use the one supplied with Nginx. Thats why I don’t just use faye. The one nginx uses is much more optimzed.

extra

  • Persistant connections
  • Going evented with Node.js
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:21:37+00:00Added an answer on May 14, 2026 at 5:21 am

    Looking at your link it seems to me that all pub/sub work is done by Nginx, Ruby code is used only to test it and send messages. Clients are still using long polling:

    In the script above, every five seconds a publisher emits a new event to our Nginx server, which in turn, pushes the data to two subscribers which have long-polling connections open and are waiting for data. Once the message is sent to each subscriber, Nginx closes their connections and the clients then immediately re-establish them to wait for the next available message.

    Nginx serves as simple retranslator for messages (very clever setup BTW, thanks for the link).

    To put it short: browsers aren’t capable for this sort of connection you trying to do. This is what WebSockets were invented for.

    Later i’ll make some code in Node.js to use this setup with Nginx (I’m interested in it too).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 356k
  • Answers 356k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer GO is not properly a TSQL command. Instead it's a… May 14, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer Is it possible for a request to be truncated perhaps… May 14, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer SuspendLayout() isn't going to have an effect, there are no… May 14, 2026 at 8:51 am

Related Questions

I'm using Visual Studio's built in web server to test and EPiServer applicaiton. When
I'm working on an iPhone game, and trying to use a UIScrollView to display
I'm designing a system which is receiving data from a number of partners in
I'm currently working on a project that utilizes a proprietary PCMCIA radio card to
I am trying to improve the performance of the threaded application with real-time deadlines.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.