Take the 2-minute tour ×

This is my first time working with node.js and I am trying to use express.io to save cookies.

I have literally carbon copied the tutorial ( https://github.com/techpines/express.io/tree/master/examples#sessions ) but I only receive this error:

root@server1 [/nodeexample]# node server.js

//Result after First Page Load
{ touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function],
  name: 'test',
  feelings: 'test' }

//Result after refresh
      expires = 'string' == typeof sess.cookie.expires
TypeError: Cannot read property 'expires' of undefined
    at /nodeexample/node_modules/express.io/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:46:47
    at process._tickCallback (node.js:415:13)

Edit: I have the main server file in /nodeexample and the client script in: /home/mysite/public_html/nodetest

I did notice the app.get does not seem to be getting called. the final alert comes back as Also, you joined undefined

The error does not appear until the second refresh, and it seems as if it does work originally.

The Code I have is:


express = require('express.io')
app = express().http().io()

// Setup your sessions, just like normal.
app.use(express.session({secret: 'monkey'}))

// Session is automatically setup on initial request.
    req.session.loginDate = new Date().toString()

// Setup a route for the ready event, and add session data.
app.io.route('ready', function(req) {
    req.session.name = req.data
    req.session.save(function() {

// Send back the session data.
app.io.route('send-feelings', function(req) {
    req.session.feelings = req.data
    req.session.save(function() {
        req.io.emit('session', req.session)



   <script src="http://localhost:7076/socket.io/socket.io.js"></script>
  var socket = io.connect('http://localhost:7076');

  // Emit ready event.
  socket.emit('ready', prompt('What is your name?'))

  // Listen for get-feelings event.
  socket.on('get-feelings', function () {
      socket.emit('send-feelings', prompt('How do you feel?'));

  // Listen for session event.
  socket.on('session', function(data) {
      message = 'Hey ' + data.name + '!\n\n' 
      message += 'Server says you feel '+ data.feelings + '\n'
      message += 'I know these things because sessions work!\n\n'
      message += 'Also, you joined ' + data.loginDate + '\n'


I am not sure if I am missing a dependency or not? I loaded it with npm install express.io

Any help is greatly appreciated!

share|improve this question
Why is the app.get part of the server commented out? what page is the client loading if there is no route? –  Benjamin Kaiser Oct 20 '13 at 4:40
I updated my question, I had tried this with the app.get commented out and having it added. I had assumed the node server should not be in the public_html folder since people would be able to access the scripts. I am still brand new to node.js and am trying to learn how it is all suppose to work. I assume its something very straightforward I am doing wrong. –  Corey Oct 20 '13 at 19:03
add comment

1 Answer

OK, so I figured it out finally, Ben led me on the right direction and it was due to the app.get function. It was a miss understanding of where the client file was suppose to be.

The req.sendfile will actually send the html to the port when it is opened. I had the client file in public_html of my website where instead it should have been in the node server folder.

This way when you go to www.whateveryoursiteis.com:7076 it would load it load the html client for you.


Run: node /node/server.js

Load: www.yoursite.com:7076

I figured this was a pretty simple mistake, this answer might help another newbie on his way

share|improve this answer
Glad I could help :) –  Benjamin Kaiser Oct 20 '13 at 23:23
add comment

Your Answer


