You are not logged in. Sign in or register.

#1 2019-06-09 00:38:58

dave
Developer
Registered: 2018-11-09
Posts: 159
Website

Simple NODEJS example

Below is a simple example of how to use the api with NODEJS.

1. Install "request" module with "npm install request".

2: Create a file named "app.js" and add the following source code:

var request = require("request")
var http = require('http');
 
let key = 'YOUR API KEY';
let name = 'YOUR NAME';
let query = 'test';

let offset = 0;
let lang = 'en';
let format = 'json';

let url = 'https://api.qmeta.net/conn.php?key=' + key + '&query=' + query + '&offset=' + offset + '&lang=' + lang + '&format=' + format;

function genHTML(html){
  let handleRequest = (request, response) => {
      response.writeHead(200, {
          'Content-Type': 'text/html; charset=utf-8'
      });
      response.write(html);
      response.end();
  };
  http.createServer(handleRequest).listen(8000);
}

request({
    url: url,
    json: true
}, function (error, response, body) {

    if (!error && response.statusCode === 200) {

        let results = body.results.list;
        var output = '<ol>';
        for(var result in results){
            let title = results[result].title;
            let link = results[result].link;
            let description = results[result].description;
            let favicon = results[result].favicon;

            output = output + '<li><a href="' + link + '"><img src="' + favicon + '" width="20px"/>' + title + '</a><br/><p>' + description + '</p></li>';
        }
        output = output + '</ol>';
        genHTML(output);
    }
})

3. Insert your data in "let key" and "let name" and the keyword in "let query".

4: Save the file.

5: Execute it in terminal with "node app.js".

6. Open "127.0.0.1:8000" in your browser.

https://github.com/dave-4k/qmeta/tree/m … pi/nodejs/


Senior-Developer and System-Administrator. Don't fuck with a Hacker's machine!

Offline