Home » Javascript » How to executing a script that is located inside a symlink dir?

How to executing a script that is located inside a symlink dir?

Posted by: admin August 19, 2018 Leave a comment

Questions:

I have two directory structure:
The first one, which is my utils project is like this

mock-utils:   
   app-mock (symlinked to app-mock)
   common
       utils.js
   node_modules
   package.json
   package-lock.json

I have another one which is the app-mock which is somewhere locally,

app-mock:
  tests
      test.js

test.js contains the following import, and the entry point for the execution is inside the mock-utils since package.json is located there:

var mocha = require('mocha');
var shield = require(‘../../common/utils.js’)

However, executing test.js from mock-utils will give the error of
Error: Cannot find module

Originally, app-mock is inside the mock-utils but it have to be separated for git. How do I adjust it so that it would be possible to execute test.js while retaining this kind of structure?

Answers: