gpt4 book ai didi

node.js - 配置 Node JS 应用程序以使用 NPM

转载 作者:搜寻专家 更新时间:2023-11-01 00:03:26 24 4
gpt4 key购买 nike

我有一个非常简单的 Node JS 应用程序,我想包含 Express JS框架。我已经使用 NPM(以及 NPM 和 Homebrew)安装了 Express,没有任何错误:

brew install npm
npm install express

我的 server.js 文件只包含:

var express = require('express');

当我运行我的应用程序时,我得到了错误:找不到模块“express”。如何告诉我的 Node 应用程序包含该库?

最佳答案

你需要告诉 Node 你的库在哪里。

摘自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');

关于node.js - 配置 Node JS 应用程序以使用 NPM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4870052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com