WebDevSimplified / url-shortener

142 stars 120 forks source link

UnhandledPromiseRejectionWarning #4

Open Madhav-Somanath opened 4 years ago

Madhav-Somanath commented 4 years ago

cant start server.

therealOri commented 4 years ago

I have the same issue. it keeps saying ShortUrl is undefined and I have not got a clue why, as I followed everything to a T.

Everything starts up and works fine but when I click the shortened link or open in new tab and it just throws that error.

In the pictures provided, If I remove the lines of code in the blue bracket I get the "Cannot Get" error page just fine. But as soon as I paste the lines of code back in. Instant error and nothing loads.

git-hubPic git-hubPic2

SumitK27 commented 4 years ago

cant start server.

Faced same problem. Got solved after installing MongoDB.

Amit998 commented 3 years ago

app.get('/:shortUrl',async (req,res) =>{

shortUrl.findOne({ short:req.params.shortUrl } ,function(err,docs){

    if (docs == null ) return res.sendStatus(404)

    count = docs['click'] + 1

    var myquery = { short:req.params.shortUrl };
    var newvalues = { $set: {click: count } };

    shortUrl.updateOne(myquery,newvalues,function(err,res){

    })
    res.redirect(docs['full'])       
})

i guess it will help

itsRajat commented 3 years ago

Got the same error. Pretty sure something's wrong with the code as the forked copy of the GitHub code throws the same error.