
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
node_simple_router
Advanced tools
Intelligent router : search for view files in you application, OR define aliases to create your own paths to your views. Futhermore, you can set parameters to be sent to your views
INSTALL :
Go to your server file :
1 - require the module and give it a name : myrouter = require('node_simple_router');
2 - add this after your application setup : app.get('*', router.manageUrl);
Module configuration (config/alias.json):
- active (bool) : if set to false, you url MUST match the path to your view file.
- alias_only (bool) : if set to true, your url segments (separated by "/", must have aliases defined, direct path to file won't work by default !).
- viewFolder : the path to your view folder.
- fileExtension : you view files extension type (ex: '.jade', '.html'). YOU CAN ONLY SET ONE FOR NOW.
- page_not_found : direct path to the view file to render in case of 404 error.
- page_default : direct path to the default view if your url points to your domain name.
======================================================================================= SETTING ALIASES (make your own urls):
* aliasing are name "matches" and you will find them in config/alias.json.
Let's take an example:
Direct path to your view file (from you views main folder) = blog/mapage/index.jade
But you want your user to be redirected to that view with that URL = http://localhost:4000/mysuperblog/mapage/home,
- OR that one : http://localhost:4000/mysuperblog/mapage/mainpage
You will have to create matches (aliases) for the three folders/files guiding to your view file :
--> blog
--> mapage
--> index
The matches in config/alias.json would look like this for the url to works :
"matches":{
"blog": {
"matchingRoutes":["mysuperblog"]
},
"index": {
"matchingRoutes":["home","mainpage"]
},
}
==> This way, http://localhost:4000/mysuperblog/mapage/home WOULD BECOME http://localhost:4000/blog/mapage/index
IDEM for http://localhost:4000/mysuperblog/mapage/mainpage
WHAT HAPPENED ?
1 - "mysuperblog", if it doesn't exists as a folder, will be replaced by its match "blog".
2 - THEN, the module will search for "mapage", in the "blog" folder. mapage exists as a folder of the same name, so it does not need an alias !
3 - FINALLY, "home" or "mainpage" are replaced by their match : "index"
4 - the module render the view !
======================================================================================= OPTIONAL - SEND PARAMETERS TO YOUR VIEWS (config/routes.json) :
Imagine your want to send a parameter to the view blog/mapage/index.jade when it's called :
1 - go to config/routes.json and add this in the "routes" node :
"blog/mapage/index": {
"locals":{
"title": "Hey, welcome on my blog !",
"analytics_tracking_code": "{some string}"
}
2 - Those parameters will be accessible threw your view with locals.title or locals.analytics_tracking_code
You can contact me at julien.bonnin.dev@gmail.com.
FAQs
Intelligent router : search for view files in you application, OR define aliases to create your own paths to your views. Futhermore, you can set parameters to be sent to your views
The npm package node_simple_router receives a total of 0 weekly downloads. As such, node_simple_router popularity was classified as not popular.
We found that node_simple_router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.