根据来自前端的文本在后端创建一个文件

Create a file on back-end, from the text coming from front-end

我正在尝试制作一个从两个不同的代码编辑器(使用 angular-ui-codemirror)抓取代码的应用程序,一个用于要测试的代码,另一个用于测试代码,并输出测试回到现场。

截至目前,我可以从两个代码编辑器中获取文本并console.logged在浏览器中输出。

我想知道如何获取该代码并将其保存到后端的文件中,这样我就可以生成一个子进程,在其上运行测试并使用 stdout.

我正在使用 angularnodeexpress 进行编码和测试,我正在使用 mocha

fs.writeFile('./yournewfile.js', newCode, function (error) {
  if (error) return callback(error)

  var Exec = require('child_process').exec;

  // change node to mocha if your newCode is mocha test code
  Exec('node ./yournewfile.js', function (error, stdout, stderr) {
    // do something here
  })
})