最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Console.log not being run when using promise in NodeJS - Stack Overflow

programmeradmin6浏览0评论

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

        console.log( 'debug-1' )
        var where = {
            pound_id: studypound_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.

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

        console.log( 'debug-1' )
        var where = {
            pound_id: study.pound_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.

Share Improve this question edited Apr 6, 2016 at 20:46 Anthony 14.3k14 gold badges65 silver badges86 bronze badges asked Apr 6, 2016 at 18:08 user3221132user3221132 4
  • so, uh, why haven't you included any errors? – Kevin B Commented Apr 6, 2016 at 18:10
  • 2 This is why you should always, always, append a .catch handler to every. single. promise. – Jared Smith Commented Apr 6, 2016 at 18:15
  • 2 study, species and threeYearsBeforeStudy are not declared. – Felix Kling Commented Apr 6, 2016 at 18:18
  • Would appreciate it if you are able to accept my answer if it helped you fix your problem, thanks. – Anthony Commented Apr 6, 2016 at 18:32
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布评论

评论列表(0)

  1. 暂无评论