Get info of given package

This commit is contained in:
danbulant 2020-02-19 17:45:56 +01:00
parent 950b76e728
commit f4dcb1d333

View file

@ -1,8 +1,11 @@
const fs = require("fs");
const request = require("./requests");
const REPO = "https://registry.npmjs.org/";
module.exports = class Package {
pkg = {};
load(path){
if(!fs.existsSync(path))throw Error("Path doesn't exists!");
@ -16,4 +19,23 @@ module.exports = class Package {
return json;
}
get(pkg){
return new Promise((res, rej) => {
if(!pkg)return rej("No package name given");
request(REPO + pkg + "/").then((res) => {
var o = JSON.parse(res);
if(o.error == "Not found"){
console.log("The package providen couldn't be found on the NPM repository");
return rej(404);
}
res("found");
}).catch(e => {
console.warn(e);
rej(e);
})
});
}
}