Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcus-sa/express-atlas
A simple routing wrapper for Express built on directory and file pattern recognition with easy import of mongoose models
https://github.com/marcus-sa/express-atlas
express mongoose-model nodejs pattern-recognition routing
Last synced: about 2 months ago
JSON representation
A simple routing wrapper for Express built on directory and file pattern recognition with easy import of mongoose models
- Host: GitHub
- URL: https://github.com/marcus-sa/express-atlas
- Owner: marcus-sa
- License: mit
- Archived: true
- Created: 2017-05-02T17:51:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-21T20:26:36.000Z (about 6 years ago)
- Last Synced: 2024-09-24T18:01:31.180Z (about 2 months ago)
- Topics: express, mongoose-model, nodejs, pattern-recognition, routing
- Language: JavaScript
- Homepage: https://npmjs.com/package/express-atlas
- Size: 51.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Express Atlas
A simple and easy-to-use routing wrapper for Express built on directory and file pattern recognition
* Works with both ES6 and CommonJS
## Installation
```$ npm install express-atlas```## Documentation
### Initialization
#### Without Mongoose
```javascript
import express from 'express'
import AtlasRouter from 'express-atlas'const app = express()
new AtlasRouter({
controllers: './controllers' // Path to controllers directory
express: app
})
```#### With Mongoose
All Mongoose models will automatically be imported```javascript
import express from 'express'
import AtlasRouter from 'express-atlas'
import mongoose from 'mongoose'const app = express()
new AtlasRouter({
controllers: './controllers' // Path to controllers directory
express: app,
mongoose: ['./models', mongoose] // arg1 path to models, arg2 mongoose module itself
})
```### Routes
Recognition is based on:
* Directories
* Filename
* Params
* MethodIncase of having multiple route names where a post and get request is being called, it's separated by the route extension instead of ```method: 'post'```
* ```{root} > controllers > auth > login.js```
Will become:
```www.example.com/auth/login```* ```{root} > controllers > auth > login-post.js```
Will become the same, but with a **post** request* ```{root} > controllers > api > index.js```
Will become:
```www.example.com/api```#### Routes without Mongoose
```javascript
export default {
method: 'get', // request typeaction: function (req, res) { // action to be called
...
}
}
```#### Routes with Mongoose
```javascript
export default {
method: 'get', // request type
params: ':title', // params
model: 'News' // Mongoose model nameaction: function (req, res, next, News) { // action to be called
const {title} = req.paramsNews.findOne({title: title}, (err, data) => {
if (err) throw errif (data) {
res.json(data)
} else {
res.send(`Nothing find for: ${title}`)
}
})
}
}