nodejs和数据库通信--如何?[英] nodejs and database communication - how?



我听说过关于nodejs和使用它写下客户服务器应用程序的好消息.但是,例如,在开发IM客户端服务器应用程序时,我无法获得Nodejs Server脚本如何与数据库服务器交谈以实际存储其数据?还是我想念一些东西,而Nodejs服务器脚本不应该这样做?如果是这样,请推我纠正方向.

我已经注意到dbslayer ,但看起来仍然在Beta中.


您需要获取一个将通信处理到所需数据库的模块. 在此处查看 in node.js..与node.js合作良好的流行数据库是 mongodb其他推荐答案


如果您想要一个内部(=嵌入式)数据库,则可以使用JavaScript编写的一个数据库,您可以像其他任何模块一样需要像 nedb nstore .如果您的WebApp不需要处理很多并发连接(例如,您为自己或小型团队制作的工具),或者使用 node webkit



I've heard much good about nodejs and writting client-server application with it. But I can't get, for example, when developing IM client-server application, how nodejs server script is supposed to talk to database server to actually store it's data? Or may be I miss something and nodejs server scripts are not supposed to do that? If so, please, push me to correct direction.

I've noticed DBSLayer, but it looks like it's still in beta.


You need to grab a module that handles the communication to the database you want. See here for a list of modules for node.js. Popular databases that work well with node.js are MongoDB, CouchDB and Redis.


As stagas says, you can use a module that handles communication if you want to use an external database.

If you want an internal (=embedded) database, you can use one written in javascript you can require like any other module such as NeDB or nStore. They are easier to use and useful if your webapp doesn't need to handle a lot of concurrent connections (e.g. a tool you make for yourself or a small team), or if you write a desktop app using Node Webkit