Require Root Beta
This package is a wrapper around node native require function that resolved your packages from your application root, your application root is where your package.json file lives.
Note: This package was not design to use in node_modules packages, it was design to use in a development environment where the application is not a node_modules package. The team will expand on this in more details in this README.
Installation is easy just copy and past the command in your terminal, assuming your terminal is pointing to your project root the package manager will handle the rest.
npm i require_root --save
After installation you only need to require the module once in your bootstrap process. This would be the main entry point of your application.
How does it work?
When you run your application require root will be added to the global application namespace, allowing you to access it from any where in your application this is a neat way to eliminate the slashes we normally used.
How to use this package?
Using this module is simple just refer to require root it take one argument the path you want to load that's it, remember require root will start looking for the file from the application root.
const module = ;
This will default to loading index.js because no file name was given.
Looking at some simple example
Loading a user model from the app directory domain, bellow you will see that we are going from app/model/UserModel, the app directory is located in the root so it will be resolved.
// UserModel.jsconst Model = ;// do what you want
Working with class
// UserController.jsconst UserModel = ;const user = ;
As noted earlier this package is not suitable for every application, this package use node current working directory to try and resolve module:
This will resolved the directory path the precess started from, so if you use this package in your node_modules package underscore require will try and resolved the module from this path.
Copyright (c) 2018 Wycliffe Peart
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.