node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

node-duckduckgo

Yet another node lib for requesting Duck Duck Go.

This one has been written in typescript (2.x or above) and can be used by javascript (es6 or above) software or by typescript software.

Examples

  • TypeScript:
import { Requester } from "node-duckduckgo";
const requester = new Requester("node-duckduckgo-example");
requester.request("bart simpsons", (err, response, body) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(body);
});
  • Javascript:
const { Requester } = require("node-duckduckgo");
const requester = new Requester("node-duckduckgo-example");
requester.request("bart simpsons", (err, response, body) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(body);
});

API

  • The requester object takes an application name in parameter:
const requester = new Requester(<YOUR APP NAME>);
  • If needed, configure the requester options:
requester.no_html = 1;
requester.no_redirect = 1;

(for information about this options see Duck Duck GO API documentation

  • Execute your request and et your result This lib is backed by Request. Results can be got by either by Request's call back or by stream:
requester.request("bart simpsons", (err, response, body) => {
 if (err) {
   console.log(err);
   return;
 }
 console.log(body);
});
requester.request("bart simpsons")
  .on("data", (data) => {
    console.log(data.toString());
  })
  .on("error", (err) => {
    console.log(err);
  });

Response format is the Duck Duck GO response

Usage

node-duckduckgo is open sources (MIT license) but it doe grant you to use Duck Duck Go. Please read this page before any usage.