-1
我希望我的server.js基本上将字符串保存到.txt文件中,以便在服务器上记录/记录日志。套接字io /节点js服务器 - 将字符串保存到服务器上的txt文件
既然你不能在server.js中使用php或jQuery,我不知道该怎么做,也没有人问过同样的问题。
你知道吗?
谢谢。
我希望我的server.js基本上将字符串保存到.txt文件中,以便在服务器上记录/记录日志。套接字io /节点js服务器 - 将字符串保存到服务器上的txt文件
既然你不能在server.js中使用php或jQuery,我不知道该怎么做,也没有人问过同样的问题。
你知道吗?
谢谢。
首先,你得到的文件系统库:
var fs = require('fs');
然后,您可以像这样的输出:
fs.writeFile("log.txt", stringText, function(error) {
if(error) throw error; // Handle the error just in case
else console.log("Success!");
});
可以使用FS模块。
这样的事情会做的工作:
let myString = "very very important string";
let fs = require("fs");
// you can use async if you prefer, check the doc
fs.writeFileSync("./myFile.txt", myString);
https://nodejs.org/api/fs.html –