1
I recently started my studies in Nodejs and Express. From what I’ve been reading, app.Leann is basically what makes the server listen to requests coming from the defined port.
But I could notice that when running an Express application it runs normally even though there is no door listening statement. In case the express runs it under the table or something? Maybe I’m asking silly, but I couldn’t find anything on the Internet to clear my doubts
This one is express-generated scaffolding. As the code shows, it has no Systener, but it works and processes incoming requests normally.
var express = require('express');
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/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
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('/', routes);
app.use('/users', users);
/// 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.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
What do you mean by "run normally"? The function of an Express application is to meet HTTP requests. If the app isn’t listening to any doors, it can’t do that.
– bfavaretto
I edited there and added the code. Take a look
– Hiago Machado
When it has no Listen the application runs on the standard Node door which is 3000.
– usuario
So when not set, Node already has a default, right?
– Hiago Machado
Take a look at your package.json. Maybe you have an npm script running the server. To be honest, I don’t know much about express.
– bfavaretto