NodeJS module

Gaël Métais edited this page Dec 27, 2016 · 15 revisions

Yellow Lab Tools is build around a core, which is a NodeJS module. The server uses the core, the CLI uses the core, and you can use if also if none of them fits your needs.

Don't hesitate to contact us before coding something around YLT, your need could be the need of the many. So adding the functionality directly into YLT would probably be great.

Requirements

Add the module inside your NodeJS project

npm install yellowlabtools --save

Example

The core returns a promise you can use this way:

var ylt = require('../lib/index');

ylt(urlToTest)

    .then(function(data) {

        console.log('Success');
        console.log(JSON.stringify(data, null, 2));

    })
    .fail(function(err) {
        
        console.log('Test failed for url: ' + url);
        console.error(err);
        
    });

Options

You can launch the test with options:

var yltOptions = {
    device: 'mobile',
    screenshot: '/my/path/screenshot.png'
};

ylt(urlToTest, options)
    .then(function(data) { });
device [String]

Use "phone" or "tablet" to simulate a mobile device (by user-agent and viewport size). Default is "desktop".

screenshot [String or false]

The path where you want the screenshot to be saved (or false if you don't want a screenshot).
The file will be a large PNG file (unlike the public API option that only stores a small JPG thumbnail).

cookie [String]

Adds a cookie for a domain. Multiple cookies can be set, using a pipe separator. Example: bar1=foo1;domain=.domain1.com|bar2=foo2;domain=www.domain2.com.

authUser [String] & authPass [String]

Username and password for basic HTTP authentication. If your authentication is not basic (form based), you might be able to copy the session cookie from your browser, paste it in the "Cookie" setting and launch a run before your cookie expires.

Result

The data attribute provided in the .then() is the entire JSON response.
See the JSON output format here.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.