更新到3.x后,Express无法找到我的节点模块

时间:2013-09-28 22:17:32

标签: node.js express pug

我以前在我的Jade模板中有以下代码:

script(src='lib/angular/angular.js')
script(src='/socket.io/socket.io.js')
script(src='js/app.js')
script(src='js/services.js')
script(src='js/controllers.js')
script(src='js/filters.js')
script(src='js/directives.js')

除了socket.io之外,所有内容都会加载。更新到3.x后,它没有正确加载,给我'Uncaught SyntaxError:Unexpected token< '并在chrome中检查时加载以下文件:

<!DOCTYPE html><html ng-app="myApp"><head><meta charset="utf8"><base href="/"><title>Angular Socket.io IM Demo App</title><link rel="stylesheet" href="/css/app.css"></head><body><h1>Angular Socket.io IM Demo App</h1><div ng-controller="AppCtrl"><div class="col"><h3>Messages</h3><div class="overflowable"><p ng-repeat="message in messages" ng-class="{alert: message.user == &quot;chatroom&quot;}">{{message.user}}: {{message.text}}</p></div></div><div class="col"><h3>Users</h3><div class="overflowable"><p ng-repeat="user in users">{{user}}</p></div></div><div class="clr"><form ng-submit="sendMessage()">Message:<input size="60" ng-model="message"><input type="submit" value="Send"></form></div><div class="clr"><h3>Change your name</h3><p>Your current user name is {{name}}</p><form ng-submit="changeName()"><input ng-model="newName"><input type="submit" value="Change Name"></form></div></div><script src="lib/angular/angular.js"></script><script src="/socket.io/socket.io.js"></script><script src="js/app.js"></script><script src="js/services.js"></script><script src="js/controllers.js"></script><script src="js/filters.js"></script><script src="js/directives.js"></script></body></html>

这只是编译后的索引页面......

我是Express的新手,现在无法弄清楚如何让它识别我的node_modules。任何帮助表示赞赏。

server.js

/**
 * Module dependencies.
 */

var express = require('express'),
    app = express(),
    path = require('path'),
    routes = require('./app/routes'),
    http = require('http'),
    socket = require('./app/routes/socket.js'),
    server = http.createServer(app);

// Hook Socket.io into Express
var io = require('socket.io').listen(server);

// Configuration

app.configure(function(){
  app.set('views', __dirname + '/app/views');
  app.set('view engine', 'jade');
  app.set('view options', {
    layout: false
  });
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.static(__dirname + '/public'));
  app.use(app.router);
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
  app.use(express.errorHandler());
});

// Routes

app.get('/', routes.index);
app.get('/partials/:name', routes.partials);

// redirect all others to the index (HTML5 history)
app.get('*', routes.index);

// Socket.io Communication

io.sockets.on('connection', socket);

// Start server

app.listen(3000);

1 个答案:

答案 0 :(得分:1)

app.listen(3000);更改为server.listen(3000);。 express / http / socket.io集成样板很难处理copypasta而不用注意。