Michael Joseph Aubry
Michael Joseph Aubry

Reputation: 13462

TypeError: Property 'locals' of object #<ServerResponse> is not a function

I am using a github project to build a chat, but it is a bit outdated using express 3x.

The code tries to pass some data into the req.locals object, the commented out code is what I did but it does not save so it does not work in my io.sockets.on('connection') function.

I am trying to use that object to get some information about a room and the users inside.

/*
 * Enter to a room
 */

exports.enterRoom = function(req, res, room, users, rooms, status){
  res.locals.room = room;
  res.locals.rooms = rooms;
  res.locals.user.nickname = req.user.username;
  res.locals.user.provider = req.user.provider;
  res.locals.user.status = status;
  res.locals.users_list = users;

  // res.locals({
  //   room: room,
  //   rooms: rooms,
  //   user: {
  //     nickname: req.user.username,
  //     provider: req.user.provider,
  //     status: status
  //   },
  //   users_list: users
  // });

  console.log(res.locals);
  res.render('room');
};

Upvotes: 0

Views: 200

Answers (1)

Jan
Jan

Reputation: 5825

You're getting the error because you're trying to invoke res.locals as a function:

 res.locals() // this executes a function

when it appears that it's not. I don't know what you're trying to do but this is probably not the way to go about it.

Upvotes: 1

Related Questions