I'm a Drupal/PHP vet, have a pretty firm understanding of AJAX/JSON, but I'm a node.js newbie. I'd like to use node.js on one of my projects but my experience so far has been pretty frustrating.

I've finally managed to get my D7 node.js config working to the point where there are no more errors on startup or on client page loads. Users seem to be authenticating just fine. But when I attempt to broadcast a message (either using the web interface or drush) nothing happens on the client side - no errors, no response. Where do I start debugging this?

Also, I have to admit I'm a bit lost on where to start with node.js. All I'm looking for is: (and forgive my vocabulary if I'm off here)

1) Have users subscribe to a node.js channel when accessing a page.
2) Create a drupal function to broadcast a message to those users.
3) I'm uncertain if I should simply use AJAX for users to send messages to the server, or if there's a node.js option to receive data from the client and pass it to a Drupal function - I figure I should use this if at all possible.
4) An understanding of what I need to implement on the client side to receive, parse, and send these messages. I notice the broadcast function uses jGrowl. Is this a library? Something implemented just for Drupal node.js?

Perhaps I'm looking for "The newbie's guide on how to implement simple chat with node.js and Drupal". I know there's a node.js chat module but I'd rather wait until I know the system is working before delving into it.

Any help would be appreciated. Thanks!

#10 nodejs_config_publish_bug_10.patch695 bytesmkadin


TrevorBradley’s picture

Well, I tried installing ChatRoom, and similarly can't receive messages. I'm presuming it's yet another misconfig issue. Here's my nodejs.config.js:

backendSettings = {

This was generated using the on-site generator. The sample config file kept giving me undefined uid error messages. This config generates no errors, but sends no messages. I do see people connecting to the chatroom channel in the debug window.

If I had to make a guess, I'd suspect the messages were never being sent, as opposed to not being received; when I refresh the chatroom there are no messages loaded.

EDIT: Turning debug on seems to verify this - I see messages about channel authentication but no message data of any kind...

beejeebus’s picture

what config do you have on the drupal side?

one thing that catches my eye about your node.js config is that it's listening on localhost - is your drupal site on the same host as a node.js process?

if you come on to IRC (freenode) and join #drupal-contribute and ping me (my nick is beejeebus) i'll be happy to help you out.

TrevorBradley’s picture

Server config: (from admin/config/nodejs/config)

Server localhost
Port 8080
Enabled on *.

I didn't see any other config on the server side.

My server is indeed the same site as my node.js instance - I'm just testing this at home for now. I'd prefer the node.js listen on localhost so that the node.js instance wasn't accessible to the outside world.

EDIT: Just dug into the code to determine what was going on. Outbound messages are being added to the message queue. I checked what sendMessage()'s result of drupal_http_request was and got the following:

    [request] => POST /nodejs/publish HTTP/1.0
Host: localhost:8080
User-Agent: Drupal (+http://drupal.org/)
Content-Length: 82

    [data] => Cannot POST /nodejs/publish
    [protocol] => HTTP/1.1
    [status_message] => Not Found
    [headers] => Array
            [x-powered-by] => Express
            [content-type] => text/plain
            [connection] => close

    [code] => 404
    [error] => Not Found

Aha! On a whim, I went to http://localhost:8080/ with my web browser and got a page with the words "Not Found". Looks like a node.js configuration error!

TrevorBradley’s picture

Title: Can't broadcast message / Starter guide? » "Node.js server configuration builder" produces faulty pubilshUrl setting
Category: support » bug

I got it. I had to tear everything apart to figure it out, but I got it.

In server.js, line 1028, is the block of node.js code that should receive publishing messages and act on them:

server.post(settings.baseAuthPath + settings.publishUrl, publishMessage);

settings.baseAuthPath is also set by server.js, line 29. Also, publishUrl is set on the next line:

      baseAuthPath: '/nodejs/',
      publishUrl: 'publish',

However, in the nodejs.config.js file I posted above, publishURL was set to:


Which meant that node.js was looking for a request at the URL "/nodejs//nodejs/publish" (settings.baseAuthPath + settings.publishUrl). (It didn't help it's also looking for a POST request and refused to answer my web browser's GET requests). It goes straight to the send404 catchall in line 1040. Commenting out the publishURL line in my nodejs.config.js file makes my site work - I can see published messages!

Now, here's the problem: publishUrl being "/nodejs/publish" in nodejs.config.js is what the Node.js server configuration builder (admin/config/nodejs/js) generates automatically. I think that's broken and needs to be fixed (at least to say that it the bit that comes after a "/nodejs/" prefix.

I'd also recommend that the server.js send404 function returns something to console.log, at least in debug mode. It would have helped me figure out what was going on a lot faster.

So much for being a node.js newbie... :)

BTW - thanks for the London DrupalCon video! It sent me on the right track for debugging what was going on.

TrevorBradley’s picture

Component: Documentation » Code

Changed Component to "Code"

beejeebus’s picture

thanks for the debugging!

so, we really need two issues: one for the bug in the config generator, and one to add more information to the 404 handler.

can you change this issue to the config generator, and create one for the debug in 404 stuff?

beejeebus’s picture

thanks for the debugging!

so, we really need two issues: one for the bug in the config generator, and one to add more information to the 404 handler.

can you change this issue to the config generator, and create one for the debug in 404 stuff?

TrevorBradley’s picture

Done! I've created 1616368 for this. This thread will henceforth be about the config generator

August1914’s picture

Thanks Trevor, #4 got me into the game.

mkadin’s picture

Here's a patch. Real easy fix. Let's get this in a new release ASAP as it could be a real time saver for folks like me trying to set nodejs up for the first time.

mkadin’s picture

Status: Active » Needs review
beejeebus’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Status: Needs review » Fixed

thanks, committed and pushed.

TrevorBradley’s picture

Thanks guys!

sahithya06’s picture

Hello beejeebus

I am unable to view the messages in the chatroom despite making the required configurations. The error which I can see when I set debug to false is "Backend authentication url not found". When it is set to true, the log specifies "body: '{"error":"Invalid service key."}' }"

I have maintained the service key specified in the config file in the "settings.php" as well using the code:
$conf['nodejs_service_key'] = 'myservicekey';

Would you be aware of what exactly is causing this problem? Is this tied to the messages not appearing inside the chatroom though I can see through the logs, that the messages are being published to the channel?

Would appreciate a quick reply.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 4c81ccc on 7.x-1.x, 8.x-1.x, 8.x-1.x-head authored by mkadin, committed by beejeebus:
    #1615362 - Fixes Node.js server configuration builder produces faulty...