Nodejs 内存存储 [英] Nodejs in-memory storage
本文介绍了Nodejs 内存存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的服务器中存储要用于所有客户端的数据?(就像聊天的消息)
How do I store data to be used for all the clients in my server? (like the messages of a chat)
推荐答案
node.js 允许您构建的服务器是一个应用程序服务器,这意味着在服务器端保留请求之间的状态.以下代码段演示了这一点:
The server that node.js allows you to build, is an application server, which means that state is preserved, between request, on the server side. The following snippet demonstrates this:
var sys = require('sys'),
http = require('http');
var number = 0;
http.createServer(function (req, res) {
console.log(req.method, req.url);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>Number is: ' + number + '</h1>');
res.end();
number++;
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
这篇关于Nodejs 内存存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文