Prepare a copy, original: http://stackoverflow.com/questions/25550819/ Error-most-middleware-like-bodyparser-is-no-longer-bundled-with-express
Edit:i have posted a fork of Brian's seed with all the changes given Below:https://github.com/lossyhorizon/angular-socket -io-seed
I found this discussion while the fighting this is my self. I am updating my copy of
Https://github.com/btford/angular-socket-io-seed before I begin a new project. I plan to submit my changes back to Brian Ford when I figure out how.
Old Package.json
"socket.io": "~0.9.16", "jade": "~0.31.2", "express": "~3.2.6"
NEW Package.json
"Socket.io": "1.1.*", "Jade": "1.6.*", "Express": "4.8.*", "Serve-favicon": "2", "Morgan": "1.3.*" , "Method-override" : "*" , Added missing, "Body-parser" : "1.8" , "ErrorHandler" : "*" , "express-session" : "*" , " Multer ": " 0.1.* "
You'll need to explicitly add the middle ware this used to being just present, one line:
var express = require(‘express‘);
becomes a bunch of lines:
VarExpress=Require(' Express '); VarFavicon=Require(' Serve-favicon '); VarLogger=Require(' Morgan '); VarMethodoverride=Require(' Method-override ' var session = require< Span class= "pun" > ( ' express-session ' var Bodyparser = require ' body-parser ' var Multer = Require ( span class= "str" > ' multer ' ); var ErrorHandler = ' ErrorHandler '
Old Setup Code:
App.Set(' Port ',Process.Env.PORT|| 3000);App.Set(' Views ',__dirname+ '/views ');App.Set(' View engine ', ' Jade ');App.Use(Express.Logger(' Dev '));App.Use(Express.Bodyparser App. (express. Methodoverride App. (express. (path. Join (__dirname, Public ' App. (app. Router
NEW Setup Code:
App.Set(' Port ',Process.Env.PORT|| 3000);App.Set(' Views ',__dirname+ '/views ');App.Set(' View engine ', ' Jade ');App.Use(Favicon(__dirname+ '/public/favicon.ico '));App.Use(Logger(' Dev '));App.Use(Methodoverride());App.Use(Session({Resave: True,Saveuninitialized: True,Secret: ' UWOTM8 ' })); Parse Application/jsonApp.Use(Bodyparser.Json()); Parse application/x-www-form-urlencodedApp.Use(Bodyparserurlencoded Extended true )); //parse multipart/form-data App.use (multer ()); app use (express. (path. Join (__dirname, Public '
This is the part of the Took me forever. Sadly once I worked this off I looked in express/lib/application.js, searched for App.listen and there are a wonderful Comm Ent that explains things quite nicely. Not sure why I is so slow to look up the source, though it looks like I am not alone in.
Demos, docs, most blogs posts, say you start your app with this, and it works, but locks us out from using Socket.io (http & HTTPS At the same time also).
App. (app. ' Port ' function () { Console. Log ( ' Express server on port ' + App. ' Port '
This was functionally the same, but makes Socket.io usage was easy. Look up the source for App.listen () and you'll see, that's what's it is doing anyway.
Could be/remain at top of file Varhttp=Require(' HTTP '); VarServer=http.Createserver(App); Delete this line if not using Socket.io VarIo=Require( ' Socket.io ' ). listen (server. Listen (app. ' Port ' function () { Console. Log ( ' Express server on port ' + App. ' Port '
I does not matter if you use the new Express ' standard ' syntax, or this syntax, the same HTTP object is used either, a nd as I recall http is a built in component to node. js anyway.
I Hope this helps someone else.
Express old and new grammar comparison