npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-path-resolver

v1.0.2

Published

Resolves path to a file in a Node Js when we require a file.

Downloads

12

Readme

file-path-resolver

Resolves path to a file in a Node Js when we require a it.

Prerequisite

* NPM : 4.0.2 or higher version
* Node: v6.9.1 or higher version

Installation

npm install file-path-resolver  --save
            or
yarn add file-path-resolver --save

What is the use ??

Most of the developers requires a files as,

var helper = require('../../../../../../../../../../lib/helper');
var dbConfig = require('../../../../../../../../../../../../configurations/db/config');

But you can require these files as using file-path-resolver.

var useFilePath = require('file-path-resolver').useFilePath;
var helper = require(useFilePath('helper'));
var dbConfig = require(useFilePath('config'));

file-path-resolver appends the .js file extension if not specified while requiring a file.

How to use ??

For the best results
* keep the name of files unique.
* keep the folder names unique, if you have multiple files with same name.

file-path-resolver can be used in Node Js project. if you are using express then, Add the following lines to your app.js file as


// app.js 
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var app = express();

/* File Path Resolver Module  */
var filePathResolver = require('file-path-resolver');
filePathResolver('root-folder-name');  // Takes name of the root folder/directory as the argument.
...

Now, you can use file-path-resolver throughout the project anywhere as shown in What is the use ?? section.

Use cases handling

# You have multiple file with same name in different folders.

Suppose you have abc.js file in aaa , bbb and ccc folder/directory. Now, you can require abc.js file from bbb as,

 /**
  * Pass the name of file as the first argument and folder/directory name as the second argument
  */
 var abc = require(userFilePath('abc','bbb'));  // Note the name of folder/directory as the argument

Here, in this case make sure that there is no folder/directory exists with same bbb and contains a file named - abc. if there another folder/directory bbb exists but do'nt has the file bbb then it has no problem.

#  You have a file with unique name throughout the project.

Suppose you have file xyz.js with unique name then you can require it as,

var abc = require(userFilePath('xyz')); // just pass the name of file as the argument.
# You don't want to include folder and files while requiring a file (present in root folder only)


/* File Path Resolver Module  */
var filePathResolver = require('file-path-resolver');
filePathResolver('root-folder-name', ['.idea', 'yarn.lock', '.gitignore']);// Note this line, carefully

Here, You have passed an array of files and folders to be ignored.

Congrats

This is all about this module.

Report issues Here.

Feel free to give your valuable comments, issues and suggestions at [email protected]

###LICENSE

MIT