Friday, 14 April 2017

How to import a module in Node js

I have two js files: MyBreakdown.js and MyService.js and I want to import the second one into the first one.

There are in different subfolders of the same directory, like this:

server/reports/plan/MyService.js 

and

serer/validation/rules/sections/MyBreakdown.js

So what I've tried in MyBreakdown.js file is to import MyService.js in two ways but none of them worked:

  1. const seasonalityService = require('server/reports/plan/myService');
  2. const seasonalityService = require('../../../../myService');

Does anyone know how to solve this? Thanks



via migea

No comments:

Post a Comment