Getting this error when running server.js.

Started http server.
   info  - socket.io started

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property 'url' of undefined
    at Function.handle (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/node_modules/connect/lib/proto.js:105:18)
    at Server.app (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/node_modules/connect/lib/connect.js:60:31)
    at Server.serverListening (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/socket.io/node_modules/policyfile/lib/server.js:136:16)
    at Server.g (events.js:156:14)
    at Server.emit (events.js:64:17)
    at Array.0 (net.js:777:10)
    at EventEmitter._tickCallback (node.js:192:40)

This is the output of npm install

require@0.4.9 ./node_modules/require 
└── uglify-js@1.0.3
express@3.0.0alpha1 ./node_modules/express 
├── mime@1.2.5
├── commander@0.5.2
├── mkdirp@0.3.1
├── debug@0.6.0
└── connect@2.1.2
socket.io@0.9.6 ./node_modules/socket.io 
├── policyfile@0.0.4
├── redis@0.6.7
└── socket.io-client@0.9.6

And this is my config file:

backendSettings = {
  "scheme":"http",
  "host":"localhost",
  "port":8080,
  "resource":"/socket.io",
  "publishUrl":"/notifications/nodejs/publish",
  "serviceKey":"54468779wifjo78fjwijowef",
  "backend":{
  	"port":80,
  	"host":"localhost",
  	"messagePath":"/nodejs/message"
  },
  "clientsCanWriteToChannels":false,
  "clientsCanWriteToClients":false,
  "extensions":"",
  "debug":true,
  "transports":["websocket",
  "flashsocket",
  "htmlfile",
  "xhr-polling",
  "jsonp-polling"],
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1};

Thanks in advance

Comments

lelizondo’s picture

After I changed

 var io = socket_io.listen(server, {port: settings.port, resource: settings.resource});

to

var io = socket_io.listen(8888);

now the server starts, but now I get

Started http server.
   info  - socket.io started
TypeError: Object #<IncomingMessage> has no method 'header'
    at /opt/lampp/htdocs/notifications/sites/all/modules/nodejs/server.js:229:31
    at callbacks (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/router/index.js:177:11)
    at param (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/router/index.js:151:11)
    at pass (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/router/index.js:158:5)
    at Router._dispatch (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/router/index.js:185:4)
    at Object.router [as handle] (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/router/index.js:45:10)
    at next (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/node_modules/connect/lib/proto.js:191:15)
    at Object.expressInit [as handle] (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/lib/middleware.js:35:5)
    at next (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/node_modules/connect/lib/proto.js:191:15)
    at Object.query [as handle] (/opt/lampp/htdocs/notifications/sites/all/modules/nodejs/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)

when trying to send a message

MiroslavBanov’s picture

I had a similar issue recently. I had nodejs installed locally on windows machine, but when I intalled it on a linux test server, I had same issues as you. Then I made a second installation locally and it failed again. Then I looked at the versions of my installed modules. Every module has the package.json file. You can find useful information like version and dependencies there.

---------------------------
WORKING
"request", "version" : "2.9.200"
"socket.io", "version": "0.9.5"
"express", "version": "2.5.9"

NOT WORKING
"request", "version" : "2.9.202"
"socket.io", "version": "0.9.6"
"express", "version": "3.0.0alpha1" - this is the culprit.

So to properly install the correct dependencies, go to the folder that contains server.js, nodejs.config.js, package.json.
run:
npm install
npm uninstall express
npm install express@2.5.9

package.json file should probably be fixed, so it is done automatically. Anyway, using something so new and rapidly changing is a pain, so such issues are bound to show up again and again.

lelizondo’s picture

Thanks. I will try that. One question. What version of node is supposed to work

MiroslavBanov’s picture

Sorry for the delay. Both 0.6.11 and 0.6.15 worked fine for me.
BTW, to get proper version of express easier, you can edit the package.json file:
chage this line:
"express": ">=2.5.8",
to
"express": ">=2.5.8 <3.0",
And then you run 'npm install', and should work OK.

lelizondo’s picture

Status: Active » Fixed

the right versions did the trick. Thanks

Status: Fixed » Closed (fixed)

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

muschpusch’s picture

#4 worked for me too.

D34dMan’s picture

After hacking package.json as suggested in #4.
I ran npm install again.
After that ran node server.js.

The server started with some warning as below.

Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ node server.js
Started http server.
   info  - socket.io started
   warn  - error raised: Error: getaddrinfo ENOENT
MiroslavBanov’s picture

#8,
Run 'npm ls' in the /sites/all/modules/contrib/nodejs directory and give us the installed modules list.

D34dMan’s picture

Thanks for the quickresponse, much appreciated.
Here is the npm ls output

Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ npm ls
Drupal-Node.js@1.0.0-rc1 e:\wamp\www\D34005\dev\sites\all\modules\contrib\nodejs

├─┬ express@2.5.10
│ ├─┬ connect@1.9.1
│ │ └── formidable@1.0.11
│ ├── mime@1.2.4
│ ├── mkdirp@0.3.0
│ └── qs@0.4.2
├── request@2.9.203
└─┬ socket.io@0.9.6
  ├── policyfile@0.0.4
  ├── redis@0.6.7
  └─┬ socket.io-client@0.9.6
    ├─┬ active-x-obfuscator@0.0.1
    │ └── zeparser@0.0.5
    ├── uglify-js@1.2.5
    ├─┬ ws@0.4.20
    │ ├── commander@0.6.1
    │ ├── options@0.0.3
    │ └── tinycolor@0.0.1
    └── xmlhttprequest@1.2.2
D34dMan’s picture

i have tried npm uninstal express and instal express@2.5.9


Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ npm ls
Drupal-Node.js@1.0.0-rc1 e:\wamp\www\D34005\dev\sites\all\modules\contrib\nodejs

├─┬ express@2.5.10
│ ├─┬ connect@1.9.1
│ │ └── formidable@1.0.11
│ ├── mime@1.2.4
│ ├── mkdirp@0.3.0
│ └── qs@0.4.2
├── request@2.9.203
└─┬ socket.io@0.9.6
  ├── policyfile@0.0.4
  ├── redis@0.6.7
  └─┬ socket.io-client@0.9.6
    ├─┬ active-x-obfuscator@0.0.1
    │ └── zeparser@0.0.5
    ├── uglify-js@1.2.5
    ├─┬ ws@0.4.20
    │ ├── commander@0.6.1
    │ ├── options@0.0.3
    │ └── tinycolor@0.0.1
    └── xmlhttprequest@1.2.2


Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ node server.js
Started http server.
   info  - socket.io started
   warn  - error raised: Error: getaddrinfo ENOENT


MiroslavBanov’s picture

Still looks like express is at 2.5.10. Are you sure there is not something wrong with your node package manager? Try installing these specific versions in a new folder and setup nodejs there. You need to copy server.js and nodejs.config.js there.

socket.io@0.9.6
express@2.5.9
request@2.9.202

D34dMan’s picture

Sorry about the report in #11, seems like i didn't copy from the terminal properly and resulted in pasting a previous output.

npm is working fine.

I uninstalled socket.io , express and request and installed specific version that you had mentioned in #12.

Below is the result.


Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ npm ls
Drupal-Node.js@1.0.0-rc1 e:\wamp\www\D34005\dev\sites\all\modules\contrib\nodejs

├─┬ express@2.5.9
│ ├─┬ connect@1.9.1
│ │ └── formidable@1.0.11
│ ├── mime@1.2.4
│ ├── mkdirp@0.3.0
│ └── qs@0.4.2
├── request@2.9.202
└─┬ socket.io@0.9.6
  ├── policyfile@0.0.4
  ├── redis@0.6.7
  └─┬ socket.io-client@0.9.6
    ├─┬ active-x-obfuscator@0.0.1
    │ └── zeparser@0.0.5
    ├── uglify-js@1.2.5
    ├─┬ ws@0.4.20
    │ ├── commander@0.6.1
    │ ├── options@0.0.3
    │ └── tinycolor@0.0.1
    └── xmlhttprequest@1.2.2


Skarj@SKARJ-PC /E/wamp/www/D34005/dev/sites/all/modules/contrib/nodejs
$ node server.js
Started http server.
   info  - socket.io started
   warn  - error raised: Error: getaddrinfo ENOENT

SocialNicheGuru’s picture

#2 worked for me:
So to properly install the correct dependencies, go to the folder that contains server.js, nodejs.config.js, package.json.
run:
npm install
npm uninstall express
npm install express@2.5.9

D34dMan’s picture

thanks for the help,

it was some issue with the settings that made it not working.

i restored the settings from the backup of nodejs.config.js and its working now.

SocialNicheGuru’s picture

I had nodejs working yesterday.

Then I upgraded my OS.

I used the repository version of nodejs from Ubuntu. When I updated my system, nodejs was updated.

I would suggest either pinning the nodejs version or using the correct version and compile on your own machine.

My error:

npm uninstall express
aegir@devmac:~/p/7/server/drupal-7.14/sites/mysite/nodejs-server$ npm install express@2.5.9
npm http GET https://registry.npmjs.org/express/2.5.9
npm http 304 https://registry.npmjs.org/express/2.5.9
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your version of node/npm: express@2.5.9
npm ERR! notsup Required: {"node":">= 0.4.1 < 0.7.0"}
npm ERR! notsup Actual: {"npm":"1.1.32","node":"0.8.0"}

npm ERR! System Linux 3.0.0-22-generic
npm ERR! command "nodejs" "/usr/bin/npm" "install" "express@2.5.9"
npm ERR! cwd /var/aegir/platforms/7/servers/drupal-7.14/sites/mysite/nodejs-server
npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32
npm ERR! code ENOTSUP
npm ERR! message Unsupported

Anonymous’s picture

Status: Closed (fixed) » Active

reopening. should fix the versions in package.json.

Anonymous’s picture

Status: Active » Fixed

committed a fix for package.json:

http://drupalcode.org/project/nodejs.git/commit/fc1c9b2

thanks all!

Status: Fixed » Closed (fixed)

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

  • Commit fc1c9b2 on 7.x-1.x, auth-refactor, 8.x-1.x, 8.x-1.x-head:
    #1537702 - fix express.js version: we're not compatible with 3.0 beta...