Monday 25 January 2016

Could somebody explain weather my nodejs "makes sense"?

Hey. First time I'm posting here. I'm not new to programming but I am completely new to Node. I was hoping somebody could check out my code and tell me if it makes sense, from a Node stand point. Are my callbacks being used correctly, do the asynchronous methods click, stuff like that.The code is basically to select info from db, convert it to a js object and then convert this object to json, before writing it back to the database.'use strict' var _ = require('lodash'); var async = require('async'); var seneca = require('seneca')({ timeout: 10 * 60 * 1000 }); var config = require('../config/config.js')(); seneca.options(config); seneca.use('postgresql-store'); seneca.ready(function(){ function run(cb){ var eventsEntity = seneca.make$('cd/events'); async.waterfall([ function(done){ eventsEntity.list$({fields:['dates']}, {limit$: 'NULL'}, done); }, function(events, done){ async.eachSeries(events, function(event, done)){ var dates_obj = JSON.parse(eventsEntity); var dates_json = JSON.stringify(dates_obj); eventsEntity = dates_json; event.save$(eventsEntity, done); } } ], cb); } } run(function (err)){ if(err){ console.log('error', err); } console.log("Done"); seneca.close(); };

Submitted January 25, 2016 at 08:34PM by adam4543

No comments:

Post a Comment