1

I have 3 js files:

  • app.js
  • server.js
  • utils.js

There is express server starts in server.js. app.js call server start from server.js. app.js is in root directory and there also is a src directory with server.js and utils.js. When I'm trying:

var utils = require('utils');

In server.js I get error:

Error: Cannot find module 'utils'

Why? utils.js and server.js are in the same directory.

Thank you.

3
  • 2
    require("./utils") !!! Commented Jun 9, 2013 at 15:20
  • 1
    Great :) Thank you. Post answer i'll mark it Commented Jun 9, 2013 at 15:21
  • 1
    Are you kidding me -_-: stackoverflow.com/questions/16990500/… Commented Jun 9, 2013 at 21:48

1 Answer 1

5

You have to write:

require("./utils")

Otherwise it will try to load utils.js from the node_modules directory.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.