套接字io / node js服务器 - 将字符串保存到服务器上的txt文件 [英] Socket io / node js server - save string to txt file on server

查看:150
本文介绍了套接字io / node js服务器 - 将字符串保存到服务器上的txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的server.js基本上将字符串保存到服务器上的历史/日志的.txt文件中。

I would like my server.js to basically save a string to a .txt file for a history/log on the server.

因为你不能使用php或者在server.js中使用jQuery,我不知道该怎么做,也没有人问过同样的问题。

Since you can not use php or jQuery in server.js, I don't know how to do this, nor has anyone asked the same question.

你知道怎么做?

谢谢。

推荐答案

首先你得到文件系统库:

First you get the file system library:

var fs = require('fs');

然后,您可以像这样输出:

Then, you can just output like this:

fs.writeFile("log.txt", stringText, function(error) {
    if(error) throw error; // Handle the error just in case
    else console.log("Success!");
}); 

这篇关于套接字io / node js服务器 - 将字符串保存到服务器上的txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆