I'm trying to follow Tomas Davis's tutorial on Backbone.js but I can't make the server run.
He gives a standard node.js server with CORS enabled and a Redis database. Here's the link to his GitHub :
--> https://github.com/thomasdavis/video-backbone-beginner-server
There was one further problem that I solved, so you'll have to replace :
nohm.setClient(redis);
by :
redis.on("connect", function() {
nohm.setClient(redis);
console.log("Nohm Connected to Redis Client");
})
After that fix, Nohm seems to connect to Redis but still doesn't work. Here's the stack-trace :
{ name: 'Nohm Error',
message: 'Did not find a viable redis client in Nohm or the model: User' }
/node-projects/backbone/node_modules/nohm/lib/properties.js:27
if (!this.properties[key]) {
^
TypeError: Cannot read property 'firstname' of undefined
at Nohm.property (/node-projects/backbone/node_modules/nohm/lib/properties.js:27:23)
at Nohm.property (/node-projects/backbone/node_modules/nohm/lib/properties.js:22:23)
at Object.<anonymous> (/node-projects/backbone/example_server.js:110:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
The Redis server process is up though. Does anyone know how to make the server work ? Thank you in advance !
Sorry for the late reply, hope it'll still be of some help.
I cannot be 100% sure what the problem here is without knowing what /node-projects/backbone/example_server.js:110 is.
But my best guess is that while you wait for the connection you are trying to do other actions with nohm. Nohm then tries to access the client before the client is connected.
This causes the init function of a model to fail, thus not properly initializing the internal variables (amongst others properties).
You need to wait with all model interaction until the redis connection is established. Or you revert to the old method of:
nohm.setClient(redis);
This should then queue up the redis commands until the connection is established, if I'm not mistaken.