1

I'm just trying to run sample codes from Developing Microservices with Node js, and it says:

var express = require('express')
var bodyParser = require('body-parser')
var cookieParser = require('cookie-parser')
var methodOverride = require('method-override')
var seneca = require('seneca')()
var argv = require('optimist').argv
var app = express()
var cors = require('cors')
var routes = require('./../routes/index')
let path = require('path')
var webpack = require('webpack')
var webpackMiddleware = require('webpack-dev-middleware')
var config = require('./../webpack.config.js')

var compiler = webpack(config)

var conf = {
   port: argv.p || 7770
}

app.engine('jsx', require('express-react-views').createEngine())
app.set('port', conf.port)
app.use(cors())
app.use('/public', express.static(path.join(__dirname,'./../public')))
app.use('/views', express.static(path.join(__dirname, './../views')))
app.use(webpackMiddleware(compiler));
app.use(cookieParser())
app.use(express.query())
app.use(bodyParser.urlencoded({extended: true}))
app.use(methodOverride())
app.use(bodyParser.json())
app.use(express.static('public'))
app.use(seneca.export('web'))  // Error line

seneca.use('./../lib/registerAPI')

app.use('/', routes)

module.exports = app

but Im getting an error that says:

/home/quocdinh/workspace/ECommerce/ass-ECommerce/node_modules/express/lib/application.js:177
     throw new TypeError('app.use() requires middleware functions');
     ^
TypeError: app.use() requires middleware functions 
     at EventEmitter.use (/home/quocdinh/workspace/ECommerce/ass-ECommerce/node_modules/express/lib/application.js:177:11)
     at Object.<anonymous> (/home/quocdinh/workspace/ECommerce/ass-ECommerce/src/app.js:33:5) // --> line: app.use(seneca.export('web'))

I have tried to find solutions but ineffective.

I tried adding

 app.use(require('seneca-web'))

but still not be

I tried to lower the version of the node version that I have to 4.0 from 6.0, but still got the same error

Dinh Luong
  • 127
  • 3
  • 15
  • Try making sure you're using the same version of express (as configured in the `package.json` file) as whatever tutorial you're following. – José Luis Oct 12 '16 at 12:40
  • this is the express version in my package.json ("express": "~4.11.2") – Dinh Luong Oct 12 '16 at 12:43
  • You'll need to make sure that you `npm install` the same version of express that is used in the tutorial. Example apps built using express 2 won't usually run cleanly using express 3 or 4, and viceversa. – José Luis Oct 12 '16 at 12:46
  • I tried the version 2, 3, 4 of express unsuccessfully – Dinh Luong Oct 12 '16 at 13:01
  • This error generally means that you are trying to call a middleware function that does not have access to the req, res, next objects. See http://expressjs.com/en/guide/using-middleware.html. I know nothing about Seneca, but I would look closely at their docs. – jjwilly16 Oct 13 '16 at 03:36

1 Answers1

0

I'm learning microservices with seneca too.
Using express version ~4.13.4 and seneca version ^2.0.0 works for me.

More information can be found in seneca getting started examples at this URL: https://github.com/senecajs-attic/getting-started

Look at their package.json file. Hope it helps!

jack-y
  • 433
  • 4
  • 12