Configuring a Node JS Application to Use NPM

I have a really simple Node JS application and I would like to enable Express JS . I installed Express with NPM (and NPM with Homebrew) without any errors using:

brew install npm
npm install express

And my file server.jscontains 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 a library?

+3
source share
2 answers

You need to tell node where your libraries 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');
+1
source

Here's the walkthrough of the npm bundle command:

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

0
source

Source: https://habr.com/ru/post/1789397/


All Articles