3

I'm working on an application with NodeJS. I'm trying to load one js file into the another using require().

My folder structure looks like:

src

  - test1

        - design

             - reports

               - components

                - foo.js

  - test2

        - services

             - bar.js

I am trying to call foo.js from bar.js using require() method.

When I do require('test1/design/reports/components/foo.js'); and run the app using grunt dev, I'm getting the following error:

Error: module "test1/design/reports/components/foo.js" not found from "(some path) test2.services.bar.js"

Can any one help to solve this?

Thanks.

3
  • 1
    surely it should be require('../../test1/design/reports/components/foo.js');? Commented Jun 2, 2014 at 12:17
  • @tfogo I think you should post it as an answer. Commented Jun 2, 2014 at 12:21
  • @RAS A-0- already has, it's fine. Commented Jun 2, 2014 at 12:25

1 Answer 1

1

yeah do this:

require('../../test1/design/reports/components/foo.js');
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working. Can u plz explain how does relative path works in node.js?
in the same way as it works in your operating system

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.