3

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?

1 Answer 1

4

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

console.log(result[0].FileContent)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.