Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass a callback funcion into an async function node js

const express = require('express');
const app = express();
const dns = require('dns');


let CheckUrl = function (url, done) {
    return new Promise((resolve, reject) => {
        dns.lookup(url, function(err, address) {
            console.log("err " , err)
            if (err) {
                resolve(false)
            } else {
                resolve(true)
            }

        });
    });
} 


app.post("/api/shorturl/new", async function(req, res) {

  try {

    let result = await CheckUrl(req.body.url);
    console.log("result " , result)
    res.send(result)
  }
  catch (error) {
    console.log("in catch error " , error)
    res.send(error)
  }
});

app.listen(3000)
Comment

PREVIOUS NEXT
Code Example
Javascript :: wast node 
Javascript :: submit form on ctrl enter 
Javascript :: .loads with whole json file 
Javascript :: copy value from one sheet to anotehr 
Javascript :: Plumasil - new item button text 
Javascript :: delete all items in an array 
Javascript :: user key value within the obj js 
Javascript :: autonumeric stimulus 
Javascript :: get object property dynamically liquid 
Javascript :: laravel , json Why it shows Cannot access offset of type string on string error 
Javascript :: React.js setState on page load not working, how to fix 
Javascript :: js num to str 
Javascript :: node js delete folder 
Javascript :: angularjs Add aria-label to table header in datatable 
Javascript :: Prevent the wiping of an Array after routing Angular.js 
Javascript :: Se Chartjs horizontal 
Javascript :: React Native : Add a band of color in the background 
Javascript :: Page Pre loader not removing 
Javascript :: upsert typeorm 
Javascript :: string split into three non empty combination js 
Javascript :: select the value of dropdownMenu with Semantic ui react 
Javascript :: cleave js 
Javascript :: chat v2 msg and time good 
Javascript :: phaser wrap sprite 
Javascript :: Sorting the Odd way! 
Javascript :: JavaScript: Cycle through three-state checkbox states 
Javascript :: communicate between content script and bg 
Javascript :: react-native navigation homeStack 
Javascript :: prisma write database 
Javascript :: Backbone View Template 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =