loopbackjs - read data from file using loopback -


i have raw data file 100 records. name - start position 0. address - start position 50.

i want read data[name , address] , validation , store information in db. please suggest how can achieved loopback.

one way approach add remote method 1 of models actual import , use packages 'csv' , 'xml' npm read files. so, basic steps are:

  1. add remote method existing model
  2. add packages npm read actual files
  3. read through files , update database.

something this:

// mymodel.js import fs = require('fs'); import xml = require('xml') import csv = require('csv')  export function import(info, callback) {      // current database connection.     var ds = this.datasource.connector;      // ***********************************************     // ** read files , write database here **     // ***********************************************     // --->     // ***********************************************      // return results and/or error information.     return callback(null, data) }  export function remotemethod(model: any) {     model.remotemethod(         'import',         {             http: { verb: 'get' },             accepts: {arg: 'info', type: 'data' },             returns: [                 { arg: 'info', type: 'data' },                 { arg: 'data', type: 'data' }             ]         }     )     return model; } 

this called using http://mydomain/api/mymodel/import using 'get'.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -