jarradseers / express-load Goto Github PK
View Code? Open in Web Editor NEWAutoload scripts (routes, controllers, models...) into an object - great for large Node / Express applications.
License: MIT License
Autoload scripts (routes, controllers, models...) into an object - great for large Node / Express applications.
License: MIT License
Hi,
Do you think it will be possible to load js files which contains '-' in names.
'myfile-name.js' for instance ?
and to retrieve it then by app.controler['myfile-name']
We have a folder structure where we store test files under src like
app
--test
----app_spec.js
app.js
In this scenario I can use regular expression to match all *.js but not *_spec.js
Hi all,
I'd like to know, if there is a manner to add a fixed prefix for routes using express load.
For example, today with express Router, I can do the following:
var router = express.Router();
var user = require('./app/services/user');
router.route('/users').get(user.list);
app.use('/api/v1/', router);
So, all my requests path will attend on: /api/v1/users
or whatever is the route that I declare on router.route.
Can I do something like it with express-load?
Thanks a lot!
[]'s
Natan Deitch
Hi,
Here my tests case, I have developped https://github.com/darul75/express-json-refiner.
Last version on npm is ok but current has the following issue.
On local it works but on Travis it fails systematicaly and make me crazy.
I use mocha for making test, on root of project I use something like
mocha test/test.spec.js
2 directories in test/model and test/access are loaded by your module in this order as in access files I get reference to some model file.
normally content are retrieved in app.model and app.access but I got some suspiscion that namepace build on travis side is something like app.test.model and app.test.access...
could you help me and fork this project to look what is wrong.
https://travis-ci.org/darul75/express-json-refiner
thx,
julien
Hello everybody
I would like to know how to split the control methods into files. When I do controllers/users/index.js the following happens:
Error: Route.get() requires callback functions but got a [object Object]
controllers/users/index.js
module.exports = (app) => {
var User = app.models.user
return {
index(req, res) {...}
}
}
Thanks a lot!
[]'s
For my folder structure, I have my models, views, controllers, and routes in a folder called app:
app/controllers/.js
app/models/.js
app/routes/.js
app/views/
express-load loads everything with app. in the name:
app.app.controllers.*
app.app.models.*
app.app.routes.*
Can there be a setting to ignore a specific base dir, for example:
{basedir: 'app'}
would strip app from the beginning so that it would result in:
app.controllers.*
app.models.*
app.routes.*
I know I could just move the controllers/models/routes into the base dir, but I would prefer to organize my project, and reduce the base dir clutter.
Edit: To add - I was previously running my code on node 0.6, and I modified express-load from "fs.existsSync" to "path.existsSync"
I started using node 0.8, and downloaded an unmodified express-load when this problem started to occur.
Imagine you have the following directory structure:
app
+++ controller
+++ model
+++ view
Now by using load('app/controller').into(app); I have to type app.app.controller.
It would be nice if we could change the "app object" and simplify the way how to access subfolders. i.e. load('app/controller', {name: 'controller'}).into(app);
folder: models/user.js
controllers/user.js
app.js
var express = require('express'), load = require('express-load');
var app = express();
load('models')
.then('controllers')
.into(app);
but
models/user.js
module.exports = function(app) {
console.log(app.controllers); // not work?
}
Can not access because it does not exist
Hi, Is there a way to only load modules, avoiding the load of sub-modules?
For example, I have a folder modules
, with a lot of scripts to load, but there is only one module which need to load your own sub-modules using require
, and I'd like to avoid the load of theses submodules.
Hi @jarradseers,
What do you think about loading cwd option from all the items? To me, it seems more intuitive.
load('models', {cwd: 'app'})
.then('controllers', {cwd: 'app'})
.then('routes', {cwd: 'config'})
.into(app)
Do you think it makes sense?
Today load()
sets the cwd param to all modules.
in development i will change express scripts very frequently,but express-load can not auto reload the script when it's already been loaded. so why not support auto reload scripts?
by the way, the cwd is very useful for me
Hi @jarradseers
Just to letting you know that things get ugly (specially on post/delete/put requests) when you load your routes before the app.use(express.bodyParser());
Express can't parse the request properly when you load your routes before it. If you make a simple POST to a route which had been declared before bodyParser the req.params
is completely empty.
It looks more like a express problem then a express-load problem but.... maybe you could do something under the hood that loads our routes on the right "timing".
I have a folder/file structure like this:
controller/
app/
token.js
token/
access.js
authorization.js
refresh.js
It would be nice to be able to extend off of app
allowing to have multiple levels. I can't seem to get it working and didn't see anything in the documentation explaining this.
Example:
controller.app.token();
controller.app.token.access(); // This doesn't work.
Hello, i have the following error
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:467:13)
at Context.<anonymous> (test/rank/rankServiceTest.js:19:3)
with the following code
var Q = require('q');
var async = require('async');
var expect = require('expect.js');
var load = require('express-load');
var app = require('../../app.js');
var mongoose = require('mongoose');
var basicMongoDbMock = require('../mockDb/basicMongoDbMock');
describe('Suite 01', function () {
before(function (done) {
this.timeout(8000);
load('config') // at Context.<anonymous> (test/rank/rankServiceTest.js:19:3)
.then('enums')
.then('models/UniqueId.js')
.then('models')
.then('modules/rank')
.into(app, function () {
});
});
beforeEach(function (done) {
mongoose.connect('mongodb://localhost:27017/squid_test');
basicMongoDbMock
.seed(Mission, Participation, User, Image)
.then(function () {
done();
});
});
afterEach(function (done) {
basicMongoDbMock
.unseed(Mission, Participation, User, Image)
.then(function () {
mongoose.disconnect(function () {
done();
});
});
});
it('Should...', function (done) {
});
});
This is the start line of the exception
load('config') // at Context.<anonymous> (test/rank/rankServiceTest.js:19:3)
Have any idea of the cause for the error?
Is?
Hi,
I'm using your library:
load('config')
.then('mongoose')
.then('models')
.then('controllers')
.then('routes')
.into('app');
And receiving an error:
Object .js,.node,.json,.coffee,.sjs has no method 'test'
Windows 7, Node v0.10.25
i have an app directory looks like
app/
├── controllers
│ ├── index.js
│ └── users.js
├── errors.js
├── models
│ └── user.js
└── other_things
in the server.js
i have the following code using express-load
load('errors', {cwd: 'app'})
.then('models')
.then('controllers')
.into(app);
but console.log(app.errors);
is undefined
and console.log(app);
show the following among many other unrelated output
'': { errors: { not_found: [Function] } } }
how do i convert that to be loaded like
'errors':{ not_found: [Function] } }
the errors.js
is defined as following
exports.not_found = function(err){
//... yada yada...
}
When I load middlewares, I don't want to call the function.
module.exports = function(options) {
return function(req, res, next) {
};
}
ReferenceError: next is not defined
at exports.isAuthenticated (.../node_modules/express-load/examples/mvc/controllers/user.js:3:5)
version 1.1.8 is not available in npm
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.