How to use needle

Comprehensive needle code examples:

How to use needle.request:

42
43
44
45
46
47
48
49
50
51
52
53
  if (url.includes(URL_CHECK_DEBUG)) console.log(msg);
}


function doGet(normUrl, callback, calls, delay, ctx) {
  let endDone = false;
  const get = needle.request('get', normUrl, null, needleOpts);


  get.on('header', (code, headers) => {
    debugLog(normUrl, `IN get header EVENT: ${normUrl}`);
    ctx.statusCode = code;

How to use needle.delete:

77
78
79
80
81
82
83
84
85
86
            callback(null, null);
        }};
    });

    expect(trello.makeRequest.bind(trello, 'DELETE', 'somePath', {}, function () {})).to.not.throw(Error);
    restler.delete.restore();
    done();
});

it('should not mutate passed options object', function (done) {

How to use needle.patch:

372
373
374
375
376
377
378
379
380
381

const data = args.slice(1).join(' ')
const BodyData = { title: data }
headers.Authorization = "Bearer " + Token

needle.patch(`https://api.twitch.tv/helix/channels?broadcaster_id=${broadcaster_id}`, BodyData, {headers: headers}, function(error, response) {
  if (!error && response.statusCode == 204) {
    CLIENTS["BOT"].say(target, `The new title is: ${data}`)
  } else {
    CLIENTS["BOT"].say(target, response.statusCode + " : " + response.body.message)

How to use needle.put:

65
66
67
68
69
70
71
72
73
74
            callback(null, null);
        }};
    });

    expect(trello.makeRequest.bind(trello, 'PUT', 'somePath', {}, function () {})).to.not.throw(Error);
    restler.put.restore();
    done();
});

it('should not throw error if a method passed is DELETE', function (done) {

How to use needle.post:

201
202
203
204
205
206
207
208
209
210
_registerUser (opts, cb) {
  const data = Object.assign(opts, {
    password_confirmation: opts.password,
    accept_terms: true
  })
  needle.post(this.BASE_URI + '/api/oauth/register', data, {
    json: true,
    headers: {
      'X-Register-Provider': 'pm2-register',
      'x-client-id': this.client_id

How to use needle.get:

59
60
61
62
63
64
65
66
67
68

for (const filenameOrUrl of filenamesOrUrls) {
    filenameForOutput = filenameOrUrl;
    let baseUrl = '';
    if (/https?:/.test(filenameOrUrl)) {
        stream = needle.get(filenameOrUrl);
        stream.on('error', onError);
        stream.on('response', onResponse);
        try { // extract baseUrl from supplied URL
            const parsed = url.parse(filenameOrUrl);