LoginSignup
1
1

More than 5 years have passed since last update.

node.jsでリクエストオブジェクトの内容をJSONでファイルに保存する

Posted at

httpserverでhandleHttpコールバックでリクエストを受けるとします。

fs = require('fs');
function handleHttp(req, res) {

    var cache = [];
    fs.writeFile("./req.txt", JSON.stringify(req, function (key, value) {
        if (typeof value === 'object' && value !== null) {
            if (cache.indexOf(value) !== -1) {
                return;
            }
            cache.push(value);
        }
        return value;
    }));
    }

これでリクエストの内容をJSONで視認できます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1