title: Node wrapper: Maximum call stack size exceeded
body: <p>I'm building a Node wrapper for an <a href="https://www.lob.com/docs" rel="nofollow">API</a> and am receiving a stack overflow error when attaching a pdf file in a <code>POST</code> request to the server.</p>
  
  <p>The core logic is in <code>src/lob.coffee</code>:</p>
  
  <pre><code>fs = require "fs"
  
  USER_AGENT = "Lob: Node Wrapper"
  
  API_HOST = "https://api.lob.com"
  API_PATH = "/v1"
  
  module.exports = lob = (api_key) -&gt;
  
    request = (method, path, data, cb) -&gt;
  
      request_object = {
        method : method,
        uri : "#{API_HOST}#{API_PATH}#{path}",
        headers : {
          "Accept" : "application/json",
          "Connection" : "close",
          "User-Agent" : USER_AGENT
        },
        auth : {
          user : api_key,
          pass : ""
        }
      }
  
      if typeof data is "function"
        cb = data
  
      r = request request_object, (err, res, body) -&gt;
        body = JSON.parse(body)
        if body.errors? and err is null
          err = body.errors
          delete body.errors
        cb err, body
        this
  
      if method is "POST_FORM"
        form = r.form()
        Object.keys(data).forEach (_k) -&gt;
          form.append _k, data[_k]
        this
  
    objects:
      createObject: (data, cb) -&gt;
        path = "/objects"
        data.file = fs.createReadStream data.file.substr 1
        request "POST_FORM", path , data, cb
  </code></pre>
  
  <p>And I wrote this basic file in <code>test/manual.coffee</code> for testing the functionality:</p>
  
  <pre><code>api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc"
  lob     = require('../src/lob')(api_key)
  
  object2 =
    name: "TEST"
    file: "@/Users/Admin/Downloads/test.pdf"
    setting_id: 100
  
  lob.objects.createObject object2, (err, res) -&gt;
    console.log err, res
  </code></pre>
  
  <p>But when I run the test file, I receive the following error: <code>ERROR: RangeError: Maximum call stack size exceeded</code>and I'm not sure what the cause of this would be.</p>