Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have folowing directory structure:

--app
  -- test
    -- server.js
  -- app.js

I try to call function in app.js which exports from server.js, i do:

var server = require("test/server");

But get error:

Error: Cannot find module 'test/server'

How can i include it correctly?

Thank you.

share|improve this question

1 Answer

up vote 3 down vote accepted

The path must be relative to the file you are currently in.

Use var server = require("./test/server");

share|improve this answer
Yes, thank you very much, it works. – 0xAX yesterday
2  
@0xAX You should select this as the correct answer if it worked and there's nothing else to add. – Sly 23 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.