Callum Linington
Callum Linington

Reputation: 14417

Node require not finding my file

So i have this directory structure

--- root
  |--- server
     |--- config
        |--- pfio
           |--- pfio-server.js
           |--- event-bus.js
  |--- server.js

In my pfio-server.js file i require the event-bus.js file so I use this:

var eventBus = require('./server/config/pfio/event-bus');

This is pretty standard, goes without saying really. However, when I run the server.js it says it can't find the module event-bus

Say what....

Upvotes: 0

Views: 82

Answers (1)

user1321425
user1321425

Reputation:

In Node, imports are relatives from the current file (if you do a relative import) so if you're in pfio-server.js you can simply require('./event-bus');

Upvotes: 2

Related Questions