node-express-mongodb-jwt-rest-api-skeleton
Version:
Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)
18 lines (15 loc) • 529 B
JavaScript
const fs = require('fs')
const modelsPath = `${__dirname}/`
const { removeExtensionFromFile } = require('../middleware/utils')
module.exports = () => {
/*
* Load models dynamically
*/
// Loop models path and loads every file as a model except this file
fs.readdirSync(modelsPath).filter((file) => {
// Take filename and remove last part (extension)
const modelFile = removeExtensionFromFile(file)
// Prevents loading of this file
return modelFile !== 'index' ? require(`./${modelFile}`) : ''
})
}