Configuration d'une application Node JS à utiliser NPM
Question
J'ai une application Node JS très simple et je voudrais inclure le cadre du express JS. J'ai installé Express avec NPM (et NPM avec Homebrew) sans erreur en utilisant:
brew install npm
npm install express
Et mon fichier server.js
ne contient que:
var express = require('express');
Quand je lance mon application, je reçois Error: Cannot find module 'express'
. Comment puis-je dire à ma demande de nœud pour inclure la bibliothèque?
La solution
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');
Autres conseils
Here's a walkthrough of using npm's bundle command:
http://intridea.com/2010/8/24/using-npm-with-heroku-node-js?blog=company
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow