简体   繁体   English

找不到模块“ serve-static” | JavaScript | 节点js

[英]Cannot find module “serve-static” | JavaScript | node js

I want to create a simple server.js file in node.js which will act as a local server. 我想在node.js中创建一个简单的server.js文件,它将充当本地服务器。

I installed the connect module by the following command 我通过以下命令安装了连接模块

npm install -g connect

And I can see the connect module inside node_modules 我可以看到node_modules内部的connect模块

Then I tried to install serve-static module as follows 然后我尝试按以下方式安装serve-static模块

npm install -g serve-static

It says packages added but I can't see the module inside node_modules. 它说添加了软件包,但是我看不到node_modules内部的模块。 And when I try to run the following server.js it throws an exception saying Cannot find module serve-static 当我尝试运行以下server.js时,它抛出异常,提示找不到模块serve-static

server.js server.js

var connect = require('connect'),
    serveStatic = require('serve-static');

var app = connect();

app.use(serveStatic("../angularjs"));
app.listen(5000);

Error 错误

Error: Cannot find module 'serve-static'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Program Files\nodejs\server.js:2:16)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

1- Install them locally 1-本地安装

npm install connect -S
npm install serve-static -S

2- OR Link them into your folder 2-或将它们链接到您的文件夹

npm link connect
npm link serve-static

3- OR Make sure that if the environment variable NODE_PATH is set correctly 3-或确保环境变量NODE_PATH设置正确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM