Ich muß einen recht großen Haufen Daten von einer Mysqldatenbank nach Mongodb schaufeln. Das ganze spielt in der Kommandozeile.
app.js
var mysql = require('mysql'); config=require('./config').production; var connection = mysql.createConnection({ host : config.mysqlHost, port : config.mysqlPort, database: config.mysqlDatabase, user : config.mysqlUser, password : config.mysqlPassword }); connection.connect(function(err){ if(err != null) { console.log(err); } connection.query("SELECT * from feeds", function(err, rows){ if(err != null) { console.log("Problem with Query " +err); } else { // Shows the result on console window console.log(rows[0]); connection.end(); } }); }); |
package.json
{ "name": "node-mysqltest", "version": "0.0.1", "private": true, "scripts": { "start": "node app" }, "dependencies": { "mysql" : "*" } } |
config.js
var config ={}; config.development = { }; config.production = { mysqlPort:3306, mysqlHost:'localhost', mysqlDatabase:'<DB>', mysqlUser: '<USR>', mysqlPassword: '<PWD>', env : global.process.env.NODE_ENV || 'production' }; module.exports = config; |