配置 Node JS 应用程序以使用 NPM [英] Configuring a Node JS App to Use NPM
本文介绍了配置 Node JS 应用程序以使用 NPM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的 Node JS 应用程序,我想包含 Express JS 框架.我已经使用 NPM(和带有 Homebrew 的 NPM)安装了 Express,使用以下方法没有任何错误:
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
而我的 server.js
文件只包含:
And my server.js
file contains only:
var express = require('express');
当我运行我的应用程序时,我收到错误:找不到模块express"
.如何告诉我的 Node 应用程序包含该库?
When I run my application I get Error: Cannot find module 'express'
. How can I tell my Node application to include the library?
推荐答案
你需要告诉 node 你的库在哪里.
You need to tell node where your libs are.
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');
这篇关于配置 Node JS 应用程序以使用 NPM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文