javascript - Node.js server no response -
i'm using node.js , express (express-generator) create website. had working fine yesterday afternoon, guess changed , doesn't work now. firewall turned off.
i following on console.
c:\website>node bin/www listening on 8080 / - - ms - - / - - ms - - / - - ms - -
each of get / - - ms - -
happens each time try go 127.0.0.1:8080
here bin/www file:
#!/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); });
and 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 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 , forward 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;
this behavior might result of incorrectly defined routes. routes should follow pattern:
var express = require('express'); var router = express.router(); /* home page. */ router.get('/', function(req, res) { res.render('index', { title: 'express' }); }); module.exports = router;
Comments
Post a Comment