shaun
shaun

Reputation: 1273

node js mysql accessing javascript object

I am querying a db from Node.JS I am trying to get access to the content of the FileContent field in CodeFile, it returns a Javascript object: result.

jsUpdateCon.query('SELECT FileContent FROM codeFile WHERE ID = ?',[msg[1]], function(err, result){
if (err) throw err;
console.log('Data received from DB:\n');
    console.log(result);
});

console output: [ RowDataPacket { FileContent: 'someContent' } ]

if I try console.log(result.RowDataPacket); I get

console output: undefined

if I try console.log(result.RowDataPacket.FileContent);

The entire node crashes with

TypeError: Cannot read property 'FileContent' of undefined

my ultimate goal would be to get

console output: someContent when using console.log(result.something.something)

What am I doing wrong?

Upvotes: 3

Views: 4640

Answers (1)

madox2
madox2

Reputation: 51911

It looks like the result is an array, try to access it like this:

console.log(result[0].FileContent)

Upvotes: 4

Related Questions