1.0.4 • Published 4 years ago
git-img-path v1.0.4
git-img-path
Node Module which is used to get the path of the images of public repo of github so that it can be used as a Assest,
Special Thanks to @amolsr
Functionality of Module
Sometime in our projects we have to add the images to s3 bucket and we get url of that image to use in out project.
But for such a small task, especially for the small projects for learning purposes using s3 is not a good option so why don't we use github to serve static file.
Requirement
- File should stored already on github to use serve statically from url
- Module will no store file on github, you have to store file manually on public repo of github.
- Internet connection is must using this module
- This module uses node-fetch
How to use this Module
Install the module in working directory
npm i git-img-path --save
Passing yourUsername, publicRepo and folder to Module to serve files
const gitImagePath = require('git-img-path'); gitImagePath.gitImages('Username', 'repoName', 'folderName').then(fileResult => { // img object have all the images // suppose use have file Vishesh.jpg, you can find it at fileResult.Visheshjpg); console.log(fileResult.Visheshjpg); // suppose you have file index.js, you can find it at fileResult.indexjs console.log(fileResult.Visheshjpg); })
OR
const { gitImages } = require('git-img-path');
const helper = async () => {
const fileResult = await gitImages('Username', 'Repo', 'FolderName').then(res => res);
console.log(fileResult.Abhimanyujpg);
// if the file name is index.js
console.log(fileResult.indexjs);
}
helper();
If the file is in main directory, no sub folder
gitImages('Username', 'Repo')
If the file name begins with Number let 1713001.jpg then the result will be at {.N1713001jpg}
NOTE
- Repo Must be Public
- File can be any extension
- Getting file from the same name
- Suppose the fileName is a.txt the find it at atxt {key}
- Return obj is of following type
{ 'key1' : 'value1', 'key2': 'value2' }
- File name spaces are ignored in key