app.js is deprecated due to express
MicFin opened this issue · 2 comments
MicFin commented
I had to make the following changes to the app.js file in order for it to work with express.
I also had to:
npm install mongoose
npm install cookie-parser
npm install express-session
npm install body-parser
npm install method-override
npm install errorhandler
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, api = require('./routes/api')
, DB = require('./accessDB').AccessDB
, protectJSON = require('./lib/protectJSON');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var errorhandler = require('errorhandler')
var app = module.exports = express();
var DB = require('./accessDB');
// Configuration
// app.configure(function(){
app.use(protectJSON);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
// app.use(express.cookieParser()); //*
app.use(cookieParser());
// app.use(express.session({ secret: 'gopalapuram' })); //*
app.use(session({secret: 'gopalapuram'}));
// app.use(express.bodyParser());
app.use(bodyParser());
// app.use(express.methodOverride());
app.use(methodOverride());
app.use(express.static(__dirname + '/../'));
// app.use(app.router);
// });
var conn = 'mongodb://localhost/custmgr';
var db;
db = new DB.startup(conn);
// development only
if ('development' == app.get('env')) {
// app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.use(errorhandler({ dumpExceptions: true, showStack: true }));
}
// production only
if ('production' == app.get('env')) {
// app.use(express.errorHandler());
app.use(errorhandler());
}
function csrf(req, res, next) {
res.locals.token = req.session._csrf;
next();
}
// Routes
app.get('/', routes.index);
// JSON API
app.get('/api/dataservice/Customers', api.customers);
app.get('/api/dataservice/Customer/:id', api.customer);
app.post('/api/dataservice/PostCustomer', api.addCustomer);
app.put('/api/dataservice/PutCustomer/:id', api.editCustomer);
app.delete('/api/dataservice/DeleteCustomer/:id', api.deleteCustomer);
app.get('/api/dataservice/States', api.states);
app.get('/api/dataservice/CustomersSummary', api.customersSummary);
app.get('/api/dataservice/CustomerById/:id', api.customer);
app.get('/api/dataservice/CheckUnique/:email', api.checkemail);
// redirect all others to the index (HTML5 history)
app.get('*', routes.index);
// Start server
app.listen(3000, function(){
console.log("CustMgr Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
DanWahlin commented
Thanks for posting the changes. This project isn't actively maintained any longer (just added a note to the readme to make that more obvious). A similar project - without custom routing though - can be found at http://github.com/danwahlin/customermanagerstandard with updated Node.js code. Great info that you posted so I'm going to leave this available for everyone.
DanWahlin commented
I decided to bring the app up-to-date with the CustomerManagerStandard project so everything has now been updated including the Node.js scripts, AngularJS version, and all of the controllers, views, factories, etc.