Author

Topic: Node.js help needed (Read 111 times)

copper member
Activity: 250
Merit: 412
Building A Crypto Empire
November 28, 2021, 06:22:03 PM
#6

How can this be fixed? I did check DB in terminal and have found the correct table with the correct params saved inside it etc, but why is node not able to get those params.
Parse the json? (.json())

See https://developer.mozilla.org/en-US/docs/Web/API/Response/json

Thanks for that.

Update: All this method is completed now.
legendary
Activity: 1946
Merit: 1427
November 25, 2021, 01:17:28 PM
#5

How can this be fixed? I did check DB in terminal and have found the correct table with the correct params saved inside it etc, but why is node not able to get those params.
Parse the json? (.json())

See https://developer.mozilla.org/en-US/docs/Web/API/Response/json
copper member
Activity: 250
Merit: 412
Building A Crypto Empire
November 23, 2021, 06:27:01 PM
#4
you need to define rows (const rows = client.query) before iterating

or maybe you can do what you're doing right now but use for r in result ?

But, errrm, what does this have to do with bitcoin? Don't think this is a general technical discussion board. Use Stackoverflow in the future.



The developer I work with have been stuck with this issue for few days now and I need help from someone experienced in js to answer this.



I seriously hope you're not paying him per hour

Thanks for the fix, I have just changed res to rows instead.

Does the forum have general tech discussion board? This question is related to a crypto method I am building in the exchange but of course had to change the names and params in the code before posting for security reasons, having that all said I still understand where you are coming from.

Regards to the developer I guess he might be busy with other projects etc, adding to that I want to say that he is not getting paid per hour but has instead % in the project.

I am looking for another dev as well to join, will you be interested in your spare time if possible? Even if it means as part time.  Shocked

try
Code:
client.query(`SELECT * FROM colours_strength_table WHERE id == ${id}`,
        function(err, rows) {
            for (let r in rows) {
               
            }
        })

Thanks for the fix it works. Appreciated.

/////////////

The second issue I am facing is json result being returned as “success”

So have changed this line to:
if (strength === null && colour === null) { return res.json("no strength and colour params found in DB": false)}

I assume the code is not fetching correctly from DB the colour and strength as per this code:
if (r["id"] === id) {
                    strength = r["strength"]
                    colour = r["colour"]


How can this be fixed? I did check DB in terminal and have found the correct table with the correct params saved inside it etc, but why is node not able to get those params.
legendary
Activity: 952
Merit: 1385
November 23, 2021, 02:56:44 PM
#3
try
Code:
client.query(`SELECT * FROM colours_strength_table WHERE id == ${id}`,
        function(err, rows) {
            for (let r in rows) {
               
            }
        })
legendary
Activity: 1946
Merit: 1427
November 23, 2021, 11:29:09 AM
#2
you need to define rows (const rows = client.query) before iterating

or maybe you can do what you're doing right now but use for r in result ?

But, errrm, what does this have to do with bitcoin? Don't think this is a general technical discussion board. Use Stackoverflow in the future.



The developer I work with have been stuck with this issue for few days now and I need help from someone experienced in js to answer this.



I seriously hope you're not paying him per hour
copper member
Activity: 250
Merit: 412
Building A Crypto Empire
November 23, 2021, 09:19:52 AM
#1
Hello guys,

The developer I work with have been stuck with this issue for few days now and I need help from someone experienced in js to answer this. I have of course changed the names of the things so it doesn’t compromise any security in the platform, code is very similar tho.


sample.js code thats causing the issue:

const getColourById = async (req, res) => {
  let id = req.query["id"]
  let strength = null;
  let colour = null;
  client.query(`SELECT * FROM colours_strength_table WHERE id == ${id}`,
        function(err, result) {
            for (let r in rows) {
                if (r["id"] === id) {
                    strength = r["strength"]
                    colour = r["colour"]
                }
            }
        })
  if (strength === null && colour === null) { return res.json("success": false)}
  return res.json({
    outputs: [
        { strength: strength, colour: colour}
    ]
  })
}

Issue being raised in Terminal:

sample.js:518
            for (let r in rows) {
                          ^

ReferenceError: rows is not defined
    at Query.callback (/home/dev/project/node/lib/apps/sample.js:518:16)
    at Query.handleError (/home/dev/project/node/node_modules/pg/lib/query.js:128:19)
    at Client._handleErrorMessage (/home/dev/project/node/node_modules/pg/lib/client.js:335:17)
    at Connection.emit (events.js:314:20)
    at /home/dev/project/node/node_modules/pg/lib/connection.js:114:12
    at Parser.parse (/home/dev/project/node/node_modules/pg-protocol/dist/parser.js:40:17)
    at Socket. (/home/dev/project/node/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


Jump to: