Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log not being run when using promise in NodeJS

This is driving me crazy. I have the code below and when I run it, I only have debug-1 print. If I comment out the where declaration I get debug-1 and debug-2 to print.

        console.log( 'debug-1' )
        var where = {
            compound_id: study.compound_id,
            species: {
                "like": ( species + "*" )
            },
            study_start: {
                "<=": study.study_start
            },
            study_start: {
                ">=": threeYearsBeforeStudy
            }
        }
        console.log( 'debug-2' )

Super peculiar. I have this block inside a promise, but I'm sure that shouldn't be an issue.


1 Answers

Add the code

process.on('unhandledRejection', console.log.bind(console))

to the top of your node file after your dependencies. That will let you know what is going wrong, it seems you are running into an error with your promise without handling it anywhere.

like image 138
Anthony Avatar answered Nov 20 '25 01:11

Anthony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!