Express 4? #159

Open
kokujin opened this Issue Aug 22, 2014 · 31 comments

Comments

Projects
None yet
@kokujin

kokujin commented Aug 22, 2014

Hi!
When would Locomotive track Express 4?

Thanks

@rogovdm

This comment has been minimized.

Show comment
Hide comment

rogovdm commented Aug 28, 2014

+1

@yuchienho

This comment has been minimized.

Show comment
Hide comment

+1

@kildem

This comment has been minimized.

Show comment
Hide comment

kildem commented Oct 13, 2014

+1

@s3cc0

This comment has been minimized.

Show comment
Hide comment

s3cc0 commented Oct 22, 2014

+1

@rogovdm

This comment has been minimized.

Show comment
Hide comment

rogovdm commented Nov 8, 2014

+2 👍

@anatolpa

This comment has been minimized.

Show comment
Hide comment

+1 =)

@throrin19

This comment has been minimized.

Show comment
Hide comment

+1

@anmonteiro

This comment has been minimized.

Show comment
Hide comment
@anmonteiro

anmonteiro Nov 26, 2014

It seems that the development of locomotive is and has been halted for a while now; the last commit was on April 9.
Since there are ~50 daily downloads from npm (source), and many dependencies are getting better and updated, I'd love to hear what @jaredhanson has to say or add about the development of this package; and eventually discuss viable options for continuing with its development.

It seems that the development of locomotive is and has been halted for a while now; the last commit was on April 9.
Since there are ~50 daily downloads from npm (source), and many dependencies are getting better and updated, I'd love to hear what @jaredhanson has to say or add about the development of this package; and eventually discuss viable options for continuing with its development.

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Nov 26, 2014

👍 I hope @jaredhanson will answer to your question @anmonteiro

kildem commented Nov 26, 2014

👍 I hope @jaredhanson will answer to your question @anmonteiro

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Nov 27, 2014

It seems that others developpers start the migration to locomotive 0.5.x here : https://github.com/drudge/locomotive/tree/feature/express4
But the last commit was on July 9

It seems that others developpers start the migration to locomotive 0.5.x here : https://github.com/drudge/locomotive/tree/feature/express4
But the last commit was on July 9

@crispen-smith

This comment has been minimized.

Show comment
Hide comment
@crispen-smith

crispen-smith Jan 14, 2015

I've been able to successfully port my older Locomotive installation to Express 4.0 by making nominal changes to the package.json, /config/environments/all.js file and config/environments/development.js file.

These changes basically involve requiring each module appropriately and calling the new stand-alone modules rather than the express.foo versions of them.

I'd be very happy to post a PR However, this is my build and there are things that I'm sure Locomotive is capable of that I'm not leveraging. so I don't feel 100% comfortable that it's a stable foundation for other development.

I've been able to successfully port my older Locomotive installation to Express 4.0 by making nominal changes to the package.json, /config/environments/all.js file and config/environments/development.js file.

These changes basically involve requiring each module appropriately and calling the new stand-alone modules rather than the express.foo versions of them.

I'd be very happy to post a PR However, this is my build and there are things that I'm sure Locomotive is capable of that I'm not leveraging. so I don't feel 100% comfortable that it's a stable foundation for other development.

@AlexeyBee

This comment has been minimized.

Show comment
Hide comment

+1

@quangv

This comment has been minimized.

Show comment
Hide comment
@quangv

quangv Mar 3, 2015

+1, hmm is Locomotive no longer active?

quangv commented Mar 3, 2015

+1, hmm is Locomotive no longer active?

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 3, 2015

@crispen-smith I have update my /config/environments/all.js file and config/environments/development.js and install express 4. But when I run my app I receive this error:

  /.../node_modules/locomotive/lib/utils.js:21
from[method] = to[method].bind(to);
                         ^
TypeError: Cannot read property 'bind' of undefined at Object.exports.forward (/.../node_modules/locomotive/lib/utils.js:21:30)
  at Application.module.exports (/.../node_modules/locomotive/lib/underlay/express.js:60:9)
  at Application.init (/.../node_modules/locomotive/lib/application.js:53:33)
  at Application.boot (/.../node_modules/locomotive/lib/application.js:353:8)
  at Object.<anonymous> (/.../web.js:43:5)
  at Module._compile (module.js:460:26)
  at Object.Module._extensions..js (module.js:478:10)
  at Module.load (module.js:355:32)
  at Function.Module._load (module.js:310:12)
  at Function.Module.runMain (module.js:501:10)

How do you successfully port your older Locomotive installation to Express 4.x??

kildem commented Mar 3, 2015

@crispen-smith I have update my /config/environments/all.js file and config/environments/development.js and install express 4. But when I run my app I receive this error:

  /.../node_modules/locomotive/lib/utils.js:21
from[method] = to[method].bind(to);
                         ^
TypeError: Cannot read property 'bind' of undefined at Object.exports.forward (/.../node_modules/locomotive/lib/utils.js:21:30)
  at Application.module.exports (/.../node_modules/locomotive/lib/underlay/express.js:60:9)
  at Application.init (/.../node_modules/locomotive/lib/application.js:53:33)
  at Application.boot (/.../node_modules/locomotive/lib/application.js:353:8)
  at Object.<anonymous> (/.../web.js:43:5)
  at Module._compile (module.js:460:26)
  at Object.Module._extensions..js (module.js:478:10)
  at Module.load (module.js:355:32)
  at Function.Module._load (module.js:310:12)
  at Function.Module.runMain (module.js:501:10)

How do you successfully port your older Locomotive installation to Express 4.x??

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

I confirm, if you used this project https://github.com/drudge/locomotive/tree/feature/express4 in the branch feature/express4 and you changed some code in your config/environments files, locomotive with express4 works.

The modifications for me concerns :

  • BodyParser
  • Connect Session
  • Connect FavIcons
  • Method Override
  • Cookie Parser

Read the Express3 to Express 4 migration for your cases

I confirm, if you used this project https://github.com/drudge/locomotive/tree/feature/express4 in the branch feature/express4 and you changed some code in your config/environments files, locomotive with express4 works.

The modifications for me concerns :

  • BodyParser
  • Connect Session
  • Connect FavIcons
  • Method Override
  • Cookie Parser

Read the Express3 to Express 4 migration for your cases

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

I'm using these modules:

var flash = require('connect-flash');
var express = require('express')
var poweredBy = require('connect-powered-by')
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var morgan = require('morgan');
var session = require('express-session');
var serveStatic = require('serve-static');
var cookieParser = require('cookie-parser');
var passport = require('passport');
var RedisStore = require('connect-redis')(express);

I start my app using server.js (https://github.com/jaredhanson/locomotive/wiki/Migrating-from-0.3.x-to-0.4.x)

if I update locomotive using the module https://github.com/drudge/locomotive/tree/feature/express4
I receive this error:

Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined at module.exports (/.../node_modules/connect-redis/lib/connect-redis.js:128:41)
at Object.<anonymous> (/.../config/environments/all.js:13:42)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Application.environment (/.../node_modules/bootable-environment/lib/index.js:44:7)
at next (/.../node_modules/locomotive/node_modules/bootable/lib/initializer.js:49:17)

any suggestion?

kildem commented Mar 5, 2015

I'm using these modules:

var flash = require('connect-flash');
var express = require('express')
var poweredBy = require('connect-powered-by')
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var morgan = require('morgan');
var session = require('express-session');
var serveStatic = require('serve-static');
var cookieParser = require('cookie-parser');
var passport = require('passport');
var RedisStore = require('connect-redis')(express);

I start my app using server.js (https://github.com/jaredhanson/locomotive/wiki/Migrating-from-0.3.x-to-0.4.x)

if I update locomotive using the module https://github.com/drudge/locomotive/tree/feature/express4
I receive this error:

Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined at module.exports (/.../node_modules/connect-redis/lib/connect-redis.js:128:41)
at Object.<anonymous> (/.../config/environments/all.js:13:42)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Application.environment (/.../node_modules/bootable-environment/lib/index.js:44:7)
at next (/.../node_modules/locomotive/node_modules/bootable/lib/initializer.js:49:17)

any suggestion?

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

I use RedisStore like this :

var connect         = require('connect'),
     RedisStore      = require('connect-redis')(connect.session);

In Express4, session part is removed and, to used it, you need to have connect module

I use RedisStore like this :

var connect         = require('connect'),
     RedisStore      = require('connect-redis')(connect.session);

In Express4, session part is removed and, to used it, you need to have connect module

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

@throrin19 are you using connect-session module?

kildem commented Mar 5, 2015

@throrin19 are you using connect-session module?

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

This is my first part for the all.js file with express4 migration :

'use strict';

var express         = require('express'),
    poweredBy       = require('connect-powered-by'),
    cluster         = require('cluster'),
    connect         = require('connect'),
    favicons        = require('connect-favicons'),
    bodyParser      = require('body-parser'),
    methodOverride  = require('method-override'),
    cookieParser    = require('cookie-parser'),
    RedisStore      = require('connect-redis')(connect.session);

module.exports = function () {
    if(cluster.isWorker || this.env === 'test') {
        var sessionStore = new RedisStore();

        // Configure application settings.  Consult the Express API Reference for a
        // list of the available [settings](http://expressjs.com/api.html#app-settings).
        this.set('views', __dirname + '/../../app/views');
        this.set('view engine', 'ejs');
        // Register EJS as a template engine.
        this.engine('ejs', require('ejs').__express);
        this.use(favicons());
        this.use(express.static(__dirname + '/../../public'));
        this.use(bodyParser.urlencoded({ limit : '10mb', extended : true}));
        this.use(connect.json({limit: '10mb'}));
        this.use(require('connect-multiparty')());
        this.use(methodOverride());
        this.use(this.router);
        this.use(cookieParser('qwerty'));
        this.use(connect.session({ key: 'express.sid', store: sessionStore, secret : 'qwerty' }));

        // ...
    }
};

This is my first part for the all.js file with express4 migration :

'use strict';

var express         = require('express'),
    poweredBy       = require('connect-powered-by'),
    cluster         = require('cluster'),
    connect         = require('connect'),
    favicons        = require('connect-favicons'),
    bodyParser      = require('body-parser'),
    methodOverride  = require('method-override'),
    cookieParser    = require('cookie-parser'),
    RedisStore      = require('connect-redis')(connect.session);

module.exports = function () {
    if(cluster.isWorker || this.env === 'test') {
        var sessionStore = new RedisStore();

        // Configure application settings.  Consult the Express API Reference for a
        // list of the available [settings](http://expressjs.com/api.html#app-settings).
        this.set('views', __dirname + '/../../app/views');
        this.set('view engine', 'ejs');
        // Register EJS as a template engine.
        this.engine('ejs', require('ejs').__express);
        this.use(favicons());
        this.use(express.static(__dirname + '/../../public'));
        this.use(bodyParser.urlencoded({ limit : '10mb', extended : true}));
        this.use(connect.json({limit: '10mb'}));
        this.use(require('connect-multiparty')());
        this.use(methodOverride());
        this.use(this.router);
        this.use(cookieParser('qwerty'));
        this.use(connect.session({ key: 'express.sid', store: sessionStore, secret : 'qwerty' }));

        // ...
    }
};
@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

if I use:

connect         = require('connect'),
RedisStore      = require('connect-redis')(connect.session);

I receive this error:

Cannot read property 'Store' of undefined
TypeError: Cannot read property 'Store' of undefined
    at module.exports (/.../node_modules/connect-redis/lib/connect-redis.js:33:22)
    at Object.<anonymous> (/.../config/environments/all.js:14:42)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Application.environment (/.../node_modules/bootable-environment/lib/index.js:44:7)
    at next (/.../node_modules/locomotive/node_modules/bootable/lib/initializer.js:49:17)

Do you start your app using server.js file? -> node server.js

kildem commented Mar 5, 2015

if I use:

connect         = require('connect'),
RedisStore      = require('connect-redis')(connect.session);

I receive this error:

Cannot read property 'Store' of undefined
TypeError: Cannot read property 'Store' of undefined
    at module.exports (/.../node_modules/connect-redis/lib/connect-redis.js:33:22)
    at Object.<anonymous> (/.../config/environments/all.js:14:42)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Application.environment (/.../node_modules/bootable-environment/lib/index.js:44:7)
    at next (/.../node_modules/locomotive/node_modules/bootable/lib/initializer.js:49:17)

Do you start your app using server.js file? -> node server.js

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

What is your connect version and connect-redis version ? I used this :

{
  'connect' : '2.29.0',
  'connect-redis' : '^2.0.0',
}

Yes, i start app using server.js file

What is your connect version and connect-redis version ? I used this :

{
  'connect' : '2.29.0',
  'connect-redis' : '^2.0.0',
}

Yes, i start app using server.js file

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

I've installed connect right now:

connect-redis: 2.2.0
connect: 3.3.4

kildem commented Mar 5, 2015

I've installed connect right now:

connect-redis: 2.2.0
connect: 3.3.4
@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

I think I should use:

 var session = require('express-session');
 var RedisStore = require('connect-redis')(session);

kildem commented Mar 5, 2015

I think I should use:

 var session = require('express-session');
 var RedisStore = require('connect-redis')(session);
@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

After test, this is your connect version, with the 2.29.0 it works fine with my code, with the latest version and connect-session, it does no works.

Try with this module : https://github.com/mpneuried/connect-redis-sessions

After test, this is your connect version, with the 2.29.0 it works fine with my code, with the latest version and connect-session, it does no works.

Try with this module : https://github.com/mpneuried/connect-redis-sessions

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

Thanks for help @throrin19, ... my last version

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

works 👍

but I have this warning:

express deprecated req.param(name): Use req.params, req.body, or req.query instead node_modules/locomotive/lib/controller.js: 50:27

kildem commented Mar 5, 2015

Thanks for help @throrin19, ... my last version

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

works 👍

but I have this warning:

express deprecated req.param(name): Use req.params, req.body, or req.query instead node_modules/locomotive/lib/controller.js: 50:27
@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 5, 2015

the method req.param is deprecated and it will be removed in next express release. I recommand you to use this.param(key, defaultvalue); in controller.

In some controllers, i use this.req.param but i haven't this warning message

the method req.param is deprecated and it will be removed in next express release. I recommand you to use this.param(key, defaultvalue); in controller.

In some controllers, i use this.req.param but i haven't this warning message

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 5, 2015

@throrin19 which version are you using? I'm using express version 4.12.2.
if I install v.4.10.x this warning doesn't appear.
(why isn't this locomotive version in npm?)

kildem commented Mar 5, 2015

@throrin19 which version are you using? I'm using express version 4.12.2.
if I install v.4.10.x this warning doesn't appear.
(why isn't this locomotive version in npm?)

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 11, 2015

i used the version 4.10.4

i used the version 4.10.4

@kildem

This comment has been minimized.

Show comment
Hide comment
@kildem

kildem Mar 11, 2015

this warning appear since express 4.11.0.
If I update these lines of code (locomotive/lib/controller.js):

Controller.prototype.params = function(name, defaultValue) {
   return this.__req.param.apply(this.__req, arguments);
 };

to:

 Controller.prototype.params = function(name, defaultValue) {
    return this.__req.params[arguments['0']];
  };

the warning disappear even on express version >= 4.11.0 :)

kildem commented Mar 11, 2015

this warning appear since express 4.11.0.
If I update these lines of code (locomotive/lib/controller.js):

Controller.prototype.params = function(name, defaultValue) {
   return this.__req.param.apply(this.__req, arguments);
 };

to:

 Controller.prototype.params = function(name, defaultValue) {
    return this.__req.params[arguments['0']];
  };

the warning disappear even on express version >= 4.11.0 :)

@throrin19

This comment has been minimized.

Show comment
Hide comment
@throrin19

throrin19 Mar 13, 2015

the problem with your modification is the defaultValue param. If your param does not exist, it's not return like your default value.

The correct way is this :

 Controller.prototype.params = function(name, defaultValue) {
    var param = this.__req.params[name];

   if (typeof param === 'undefined') {
     return defaultValue;
   }
   if (param === null) {
     return defaultValue;
   }
    return param ;
  };

the problem with your modification is the defaultValue param. If your param does not exist, it's not return like your default value.

The correct way is this :

 Controller.prototype.params = function(name, defaultValue) {
    var param = this.__req.params[name];

   if (typeof param === 'undefined') {
     return defaultValue;
   }
   if (param === null) {
     return defaultValue;
   }
    return param ;
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment