且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Node.js连接找不到静态

更新时间:2023-11-18 16:55:52

connect软件包在其代码库的最新3.x版本中进行了一些更改,将static中间件移至其自己的软件包中. 您可以查看已移至此处的软件包列表.

The connect package has made some changes in the latest 3.x version of their code base, moving the static middleware to it's own package. You can view the list of packages that have been moved here.

因此,您有两个选择:

选项1
您可以安装旧的2.x版本的connect并按原样使用:

Option 1
You can install an older, 2.x version of connect and use that as is:

$ npm install connect@2.X.X

$ npm install connect@2.X.X

安装最新的2.X.X版本将使您当前的实现正常运行.

Installing the latest 2.X.X version will allow your current implementation to function properly.

选项2
您可以继续使用3.x版本的connect,还可以添加serve-static:

Option 2
You can continue to use the 3.x version of connect, and also add serve-static:

$ npm install serve-static

$ npm install serve-static

您还必须更新server.js文件以包括新的serve-static模块:

You would also have to update your server.js file to include the new serve-static module:

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

var app = connect();

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