Creating a JSON Array in node js

前端 未结 3 550
北荒
北荒 2021-02-07 14:08

I need to create in my server written in node js a JSON string to be sent to the client when this request it. The problem is that this JSON depends on the available data in the

3条回答
  •  旧巷少年郎
    2021-02-07 14:34

    This one helped me,

    res.format({
            json:function(){
                                var responseData    = {};
                                responseData['status'] = 200;
                                responseData['outputPath']  = outputDirectoryPath;
                                responseData['sourcePath']  = url;
                                responseData['message'] = 'Scraping of requested resource initiated.';
                                responseData['logfile'] = logFileName;
                                res.json(JSON.stringify(responseData));
                            }
        });
    

提交回复
热议问题