Have ideas to improve npm?Join in the discussion! »

    This package has been deprecated

    Author message:

    delete

    @karavel/karavel-root
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.1 • Public • Published

    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.

    Install

    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.

    require('require_root');

    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 = require_root('/');

    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.js
     
    const Model = require_root('app/model/BaseModel');
     
    class UserModel extends Model{
     
        // do what you want
    }

    Working with class

    // UserController.js
     
    const UserModel = require_root('app/model/UserModel');
     
    const user = new UserModel();

    Caveat

    As noted earlier this package is not suitable for every application, this package use node current working directory to try and resolve module:

    process.cwd()

    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.

    LICENSE

    MIT License

    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.

    Install

    npm i @karavel/karavel-root

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    5.27 kB

    Total Files

    5

    Last publish

    Collaborators