Question

var cradle = require('cradle');
var db = new(cradle.Connection)().database('starwars');

db.get('vader', function (err, doc) {
    doc.name;
    assert.equal(doc.force, 'dark');
});

db.save('skywalker', {
    force: 'light',
    name: 'Luke Skywalker'
}, function (err, res) {
    if (err) {
        // Handle error
    } else {
        // Handle success
    }
});

installed cradle via npm

npm install cradle

The error output running node cradle.js

root@server:~# node cradle.js

/root/cradle.js:5
    doc.name;
       ^
TypeError: Cannot read property 'name' of undefined
    at Object.callback (/root/cradle.js:5:8)
    at /root/node_modules/cradle/lib/cradle.js:276:26
    at IncomingMessage.<anonymous> (/root/node_modules/cradle/lib/cradle.js:210:21)
    at IncomingMessage.emit (events.js:81:20)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at Socket.ondata (http.js:1213:22)
    at Socket._onReadable (net.js:681:27)
    at IOWatcher.onReadable [as callback] (net.js:177:10)

UPDATE: problem boils down to

db.get('vader', function (err, doc) {
        doc.name;
        assert.equal(doc.force, 'dark');
    });

it's complaining about doc.name

Where can I view the database so I can see the new row added?

Was it helpful?

Solution

db.get('vader', function (err, doc) {
    if (err) {
        console.log(err);
    } else {
        doc.name;
        assert.equal(doc.force, 'dark');
    }
});

The example doesn't do error handling. I would assume the error is document vader doesn't exist or database starwars doesn't exist.

If you have couch installed and running then the database lives at http://localhost:5984/_utils/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top