Node.js服务器没有响应

时间:2014-09-10 15:50:45

标签: javascript node.js

我使用NODE.js和Express(快速生成器)来创建网站。我昨天下午工作得很好,但我想我改变了一些东西,现在还没有用。我的防火墙已关闭。

我在控制台上获得以下内容。

C:\website>node bin/www
Listening on 8080
Get / - - ms - -
Get / - - ms - -
Get / - - ms - -

每次尝试转到我的Get / - - ms - -

时,每个127.0.0.1:8080都会发生

这是我的bin / www文件:

#!/usr/bin/env node
var debug = require('debug')('test');
var app = require('../app');

app.set('port', process.env.PORT || 8080);

var server = app.listen(app.get('port'), function() {

  console.log("Listening on " + server.address().port);

  debug('Express server listening on port ' + server.address().port);
});

我的app.js:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handler

// production error handler
app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    console.log(err);
});

module.exports = app;

1 个答案:

答案 0 :(得分:0)

此行为可能是错误定义的路由的结果。您的路线应遵循以下模式:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res) {
  res.render('index', { title: 'Express' });
});

module.exports = router;