nodejs - first argument must be a string or Buffer - when using response.write with http.request

前端 未结 8 1949
难免孤独
难免孤独 2020-12-24 11:29

I\'m simply trying to create a node server that outputs the HTTP status of a given URL.

When I try to flush the response with res.write, I get the error: throw new T

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 11:47

    Although the question is solved, sharing knowledge for clarification of the correct meaning of the error.

    The error says that the parameter needed to the concerned breaking function is not in the required format i.e. string or Buffer

    The solution is to change the parameter to string

    breakingFunction(JSON.stringify(offendingParameter), ... other params...);
    

    or buffer

    breakingFunction(BSON.serialize(offendingParameter), ... other params...);
    

提交回复
热议问题