繁体   English   中英

用Node.js的FileSystem(fs)模块将多个DOM元素保存和加载为JSON的最干净方法是什么?

[英]What is the cleanest way to save and load multiple DOM elements as JSON with the FileSystem(fs) Module from Node.js?

我需要将动态添加的DOM元素(可拖动的DIV)保存到文件中,并在以后加载它们。 什么是最干净的方法来做到这一点?

您可以保存mySql或Mongodb

var mysql      = require('mysql');
var connection = mysql.createConnection({
    host     : 'locahost',
    user     : 'foo',
    password : 'bar',
    database : 'test'
});

// the callback inside connect is called when the connection is good
connection.connect(function(err){
    var sql = "select 'Joe' as name from dual";

    connection.query(sql, function(err, rows, fields) {
        if (err) return console.log(err);
        //  you need to end your connection inside here.
        connection.end();
        console.log(rows[0].name);
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM