nodejs错误undefined不是一个函数

时间:2015-08-03 15:25:52

标签: javascript node.js

我正在尝试使用节点js创建一个简单的Web服务器。这是我写的脚本。

C:\Program Files\nodejs\server.js:4
       connect.static("../angularjs")
                     ^
TypeError: undefined is not a function
    at Object.<anonymous> (C:\Program Files\nodejs\server.js:4:22)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

我将脚本放在nodejs目录中,然后尝试使用命令&#34; node server.js&#34;运行它。我收到以下错误

void processTcpPacket(StateObject tcpControl)
{
    abcMessage abc = new abcMessage();
    abc.parse(tcpControl.buffer,tcpControl.size)
    if(abc.complete)
    {
        do something with this message()
    }else if abc.multipart{
        hold this message somewhere until the next part shows up... ?
    }else{
        discard unparseable message()
    }
}

我是javascript的新手并请求您指导。

谢谢&amp;问候 苏尼

2 个答案:

答案 0 :(得分:1)

您的连接版本在其属性中不包含静态, 您要么降级您​​的connect(2.xx)版本,要么尝试此代码段

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

var app = connect();

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

但在开始之前

npm install serve-static 

答案 1 :(得分:1)

因为<StackPanel Margin="5" Orientation="Horizontal"> <TextBlock Text="ID: "/> <TextBox IsReadOnly="True" FontSize="25" Name="Pass" BorderThickness="0" Foreground="Orange" Background="Transparent" /> </StackPanel> 不是static的属性。

根据phrase

  

serve-static - 以前是静态的

我认为您使用的连接版本比您编写的连接版本更新。

所以你有两个解决方案:

  • 使用旧版connect
  • 使用connect中间件代替serve-static方法