3

I have a really simple Node JS app and I'd like to include the Express JS framework. I've installed Express with NPM (and NPM with Homebrew) without any errors using:

brew install npm
npm install express

And my server.js file contains only:

var express = require('express');

When I run my application I get Error: Cannot find module 'express'. How can I tell my Node application to include the library?

2 Answers 2

1

You need to tell node where your libs are.

extract from http://nodejs.org/api.html

require.paths
An array of search paths for require(). This array can be modified to add custom paths.

Example: add a new path to the beginning of the search list

require.paths.unshift('/usr/local/node');
Sign up to request clarification or add additional context in comments.

2 Comments

Does a solution exist that supports deploying specifically NPM packaged projects? I noticed that NPM supports a 'bundle' command but I couldn't figure out how to use it...
Can't help with that I'm afraid, I haven't tried bundle out. Lots of projects, seem to bundle their deps in and require those ones specifically.
0

Here's a walkthrough of using npm's bundle command:

http://intridea.com/2010/8/24/using-npm-with-heroku-node-js?blog=company

Comments

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.