Configuring a Node JS App to Use NPM
Pergunta
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?
Solução
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');
Outras dicas
Here's a walkthrough of using npm's bundle command:
http://intridea.com/2010/8/24/using-npm-with-heroku-node-js?blog=company
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow