注意:我已经尝试过here的其他解决方案,但它没有用
NodeJs的新手 . 我正在尝试关注AngularJS专业版,并坚持设置NodeJs服务器 . 根据书,我安装了nodejs然后使用npm install connect安装了connect包
然后在nodejs文件夹旁边的文件夹中下载angularjs . 然后编写server.js文件以连接到服务器 . 这是文件的内容:
var connect = require('connect');
connect.createServer(connect.static("../angularjs")).listen( 5000);
当我使用以下命令运行此server.js文件时:
node server.js
我收到以下错误:
function app(req, res, next){ app.handle(req, res, next); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
has no method 'static'
at Object.<anonymous> (C:\web\nodejs\server.js:2:36)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
任何想法的家伙?谢谢 .
4 回答
你可能想尝试这样的事情
dylants的答案很有帮助 . 但是,以下是我为解决相同错误而遵循的确切步骤 . 1.在命令窗口中,将目录更改为nodeJS的安装目录 . 2.运行npm install connect后,运行:
3.使用以下代码创建名为server.js的文件:
node server.js
这应该工作 . 这是我的目录配置:C:\ NodeJSInstallLocation \ angularjs
connect包在其最新的3.x版本的代码库中进行了一些更改,将
static
中间件移动到它自己的包中 . You can view the list of packages that have been moved here .所以你有两个选择:
Option 1
您可以安装较旧的2.x版本的connect并按原样使用:
安装最新的2.X.X版本将使您当前的实现正常运行 .
Option 2
您可以继续使用3.x版本的connect,并添加
serve-static
:您还必须更新
server.js
文件以包含新的serve-static
模块: