0

When I run Express.js with command "node app", it's runs and then ends!

My platforms are a Ubuntu and Windows 7 installation. I have this problem in both of them!

I copy these from CMD:

C:\> cd express

C:\express> node app

C:\express>

My App.js is like this:

var express = require('express'); var http = require('http'); var path
= require('path'); var favicon = require('static-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser');

var routes = require('./routes'); var users =
require('./routes/user');

var app = express();

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

app.use(favicon()); app.use(logger('dev'));
app.use(bodyParser.json()); app.use(bodyParser.urlencoded());
app.use(cookieParser()); app.use(express.static(path.join(__dirname,
'public'))); app.use(app.router);

app.get('/', routes.index); app.get('/users', users.list);

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

/// error handlers

// development error handler // will print stacktrace if
(app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
        res.render('error', {
            message: err.message,
            error: err
        });
    }); }

// production error handler // no stacktraces leaked to user
app.use(function(err, req, res, next) {
    res.render('error', {
        message: err.message,
        error: {}
    }); });


module.exports = app;
4
  • 2
    Please post your app.js file... Commented Jun 8, 2014 at 8:26
  • I posed app.js Above ! Commented Jun 8, 2014 at 9:06
  • did you run npm install? Commented Jun 8, 2014 at 9:11
  • When I copy Express From Some Where That Works! It works correctly Here! :| I think it from versions or Like This But I Couldn't solve it! Commented Jun 8, 2014 at 9:25

1 Answer 1

2

You aren't listening for any calls. You need to add app.listen(3000) at the end (but before exporting) to listen on port 3000.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.