-1
In an application nodejs I get this error message:
Version:
Date of publication: 8.9.2
npm: 5.5.1
express: 4.15.5
Error image:
Code from the app.js
/**
* Module dependencies.
*/
var http = require('http');
var express = require('express');
var routes = require('./routes');
var user = require('./routes/users');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var methodOverride = require('method-override');
var session = require('express-session');
var bodyParser = require('body-parser');
var multer = require('multer');
var errorhandler = require('errorhandler')
var app = express();
//load customers route
var customers = require('./routes/customers');
var app = express();
var connection = require('express-myconnection');
var mysql = require('mysql');
// all environments
app.set('port', process.env.PORT || 4300);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
var logger = require('morgan');
app.use(logger)
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(errorhandler());
}
/*------------------------------------------
connection peer, register as middleware
type koneksi : single,pool and request
-------------------------------------------*/
app.use(
connection(mysql,{
host: 'localhost', //'localhost',
user: 'root',
password : '',
port : 3306, //port mysql
database:'nodejs'
},'pool') //or single
);
app.get('/', routes.index);
app.get('/customers', customers.list);
app.get('/customers/add', customers.add);
app.post('/customers/add', customers.save);
app.get('/customers/delete/:id', customers.delete_customer);
app.get('/customers/edit/:id', customers.edit);
app.post('/customers/edit/:id',customers.save_edit);
app.use(app.router);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
By mistake,
user.list
is not defined. How you defined this function?– Woss
not defined.. I will comment on
– alexjosesilva
You can’t understand it like that. You use an object that’s not defined, you make an error saying it’s not defined and you don’t know what’s wrong? : t
– Woss
var express = require('express'); var router = express. Router(); /* GET users Listing. */ router.get('/', Function(req, res, next) { res.send('Respond with a Resource'); }); module.Exports = router;
– alexjosesilva
this is the user.js code
– alexjosesilva