express-api-versioning
express-api-versioning copied to clipboard
It's showing TypeError: expressApiVersioning is not a function
app.use(expressApiVersioning({ apiPath: path.join(__dirname, './api'), test: //api/(v[0-9]+).*/, entryPoint: 'index.js', instance: null }, (error, req, res, next) => { console.log(error); next(); })); ^
TypeError: expressApiVersioning is not a function
I see two disturbing things in the snippet. First, test should be....
test: /\/api/(v[0-9]+).*/,
escape the forward slash. Secondly, instance should be your app, so the instance line should be...
instance: app
Try this and if you still get errors then you will have to show me your directory structure
If this is hosted on a remote repo.... then you could share the link
@ProfJigsaw I don't think you're exporting properly.
I got it to work:
// Instead of this:
const expressApiVersioning = require('express-api-versioning');
// do this
const expressApiVersioning = require('express-api-versioning').default;
Hi, I am using const expressApiVersioning = require('express-api-versioning').default;
now & following exactly your mock link.
Directory Structure
app.js
api
v1
index.js
routes
index.js
v2
index.js
routes
index.js
in root app.js
const expressApiVersioning = require('express-api-versioning').default;
const app = express();
const config = {
apiPath: path.join(__dirname, './api'),
test: /\/api\/(v[0-9]+).*/,
entryPoint: 'index.js',
instance: app
};
app.use(expressApiVersioning(config, (error, req, res, next) => {
console.log(error);
next();
}));
Then in api>v1>index.js
import routes from './routes';
export default (app) => { //console.log(app)
app.use('/api/v1', routes);
};
In api>v1>routes>index.js
import express from 'express';
const router = express.Router();
router.get('/', (req, res) => res
.send({
message: 'You are in /api/v1 end point'
}));
export default router;
Now I am getting the 404
error with this message The current route is not found. Please try different route
for http://localhost:3001/api/v1
although error
coming as null
Please help. Thanks.
Hey @206577873 maybe file your issue as a separate issue? It doesn't appear related to this one.
I'm just seeing this now. Sorry I've been busy with other things.
@206577873 have you been able to fix the issue now?