El Bear
El Bear

Reputation: 13

Cannot read property 'swaggerUi' of undefined

Having a problem where the following code returns Cannot read property 'swaggerUi' of undefined each time I run node app.js. The code below is the entirety of app.js.

I have tried a bunch of different npm installs, computer restarts, and all of that. Nothing seems to change it.

var SwaggerExpress = require('swagger-express-mw');
var app = require('express')();
module.exports = app; // for testing

var config = {
  appRoot: __dirname // required config
};

SwaggerExpress.create(config, function(err, swaggerExpress) {
  if (err) { throw err; }

  // install middleware
  swaggerExpress.register(app);

  var port = process.env.PORT || 10010;
  app.use(swaggerExpress.runner.swaggerTools.swaggerUi());
  app.listen(port, function() {
    console.log('Server running at http://127.0.0.1:' + port + '/');
  });

  if (swaggerExpress.runner.swagger.paths['/hiMom']) {
    console.log('try this:\http://127.0.0.1:' + port + '/docs');
  }
});

Upvotes: 0

Views: 1903

Answers (2)

El Bear
El Bear

Reputation: 13

SOLVED: I'm not sure what the problem was, but getting a fresh clone of the GitHub repo solved the problem.

Upvotes: 0

IamJMBassey
IamJMBassey

Reputation: 71

Here is a github sample link that might be be helpful sample-swagger-for-nodejs.

Upvotes: 1

Related Questions