Skip to main content

Importer

This service allows you to import JSON data easily.

Features#

  • Import data, under the form of JSON-formatted arrays
  • Allow to create different kind of import actions
  • The import action will be called once per items in the JSON array

Dependencies#

  • None

Install#

$ npm install @semapps/importer --save

Usage#

const { ImporterService } = require('@semapps/importer');
const path = require('path');
module.exports = {
mixins: [ImporterService],
settings: {
importsDir: path.resolve(__dirname, '../imports'),
allowedActions: ['createObject']
},
actions: {
// Called once per items in array
createObject(ctx) {
const { data, userId } = ctx.params;
// Handle stuff here...
}
}
};

Importing data#

Start Moleculer in REPL mode and call the import action like this:

mol$ call importer.import --action createObject --fileName objects.json

Any other parameter you give will be passed to the action.

Service settings#

PropertyTypeDefaultDescription
importsDirstringrequiredDirectory where the JSON files are located
allowedActionsarrayrequiredList of allowed import actions

Actions#

import#

Parameters#
PropertyTypeDefaultDescription
actionstringrequiredName of the action
fileNamestringrequiredName of the file, located in the baseDir directory

Any other parameter you give will be passed to the action.