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

hacken

v1.0.2

Published

Hacken is a node module to help people in hackathons, it has almost all the common features a person needs from database operations to sockets. If you are the one who struglles with MongoDb ObjectId, hacken makes it easier to work with then too.

Downloads

11

Readme

What is hacken?

Hacken is a node module to help people in hackathons, it has almost all the common features a person needs from database operations to sockets. If you are the one who struglles with MongoDb ObjectId, hacken makes it easier to work with then too.

Contents


Object Functions

isObjValid

To Check if ObjectId is valid.

var hacken = require('hacken');

if(hacken.isObjValid(objid)){
	console.log("Valid.");
}
else{
	console.log("Invalid.");
}

toObjId

To convert a ObjectId string to underlying ObjectId.

var hacken = require('hacken');

try{
	var objid = hacken.toObjId(req.body.id);
}
catch(e){
	console.log(e.err);
}

arrObjMap

To get some specific values of properties from an array of objects.

var hacken = require('hacken');

var arr = [{ele1:"one",ele2:"two"},{ele1:"1",ele2:"2"}];

var prop = ["ele1"]; //specify properties which you want to get from an array.

var res = hacken.arrObjMap(arr,prop); //res = ["one","1"];

JWT Functions

issueToken

To Issue A Json Web Token.

var hacken = require('hacken');

var data = "hello hacken";

var secret = "adsasdAFD5454asdasd5Basasdajsdb46555654d656464N15465as4d6546546a";

var time = "5d"; //time can be given in 'd' for days without any suffix means seconds eg: 1100 for 1100 seconds.

try{
	hacken.issueToken(data,secret,time).then((token)=>{
		console.log(token);
	},(err)=>{
		console.log(err);
	});
}
catch(e){
	console.log(e);
}

verifyToken

To Verify a Json Web Token.

var hacken = require('hacken');

var token = req.params.token;

var secret = "adsasdAFD5454asdasd5Basasdajsdb46555654d656464N15465as4d6546546a"; //same as the one provided before.

try{
	hacken.verifyToken(token,secret).then((result)=>{

		var msg = result.msg;
		var decodedData = result.decoded
		console.log(msg);
		console.log(decodedData);

	}).catch((err)=>{
		console.log(err);
	})
}
catch(e){
	console.log(e);
}

decodeToken

To Decode the token.

var hacken = require('hacken');

try{
	hacken.decodeToken(token).then((res)=>{
		console.log(res);
	},(err)=>{
		console.log(err);
	});
}
catch(err){
	console.log(err);
}

MongoDb Connection

mongoConnect

To Connect To MongoDb.

var hacken = require('hacken');

var url = "mongodb://localhost:27017/db"; //replace with your url 

hacken.mongoConnect(url).then((msg)=>{
	console.log(msg);
}).catch((err)=>{
	console.log(err);
})

User Functions

Following Properties Are allowed in User Model:

  • username
  • password
  • phoneno
  • email
  • name
  • age
  • address
var object = {username:"value",password:"value",phoneno:"value",email:"value",name:"value",age:"value",address:"value"};

//These objects can also take subset of the above mentioned properties.

//Example:

var object = {username:"value",password:"value",phoneno:"value"};

userCreate

To Create The User.

var hacken = require('hacken');

hacken.userCreate(object).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

userRemove

To Remove the user.

var hacken = require('hacken');

hacken.userRemove(req.body.username).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

userLogin

To Log user in.

var hacken = require('hacken');

hacken.userLogin(username,password).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

userUpdate

To Update The User, Requires the same object with properties as used while creating the user.

var hacken = require('hacken');

//Do Not Provide Password While updating as passwords are encrypted while storing.

hacken.userUpdate(username,object).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

userFindByUsername

To Find the user by username.

var hacken = require('hacken');

hacken.userFindByUsername(username).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

userFindByName

To Find users by name.

var hacken = require('hacken');

hacken.userFindByName(name).then((result)=>{
	console.log(result); //result is an array of users.
}).catch((err)=>{
	console.log(err);
});

userFindById

To Find user by ObjectId.

var hacken = require('hacken');

hacken.userFindById(object).then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
})

msgFind

To Fetch messages of a room. //For Now roomid = "broadcast".

var hacken = require('hacken');

hacken.msgFind("broadcast").then((result)=>{
	console.log(result);
}).catch((err)=>{
	console.log(err);
});

roomFind

To Find all the chatrooms a user is associated to.

var hacken = require('hacken');

var username = req.body.username;

var page = req.body.pagenum; //to paginate the response as there can be many chat rooms for a user.

var length = req.body.numrooms; //to specify the number of chatrooms per page.

hacken.roomFind(username,page,length).then((result)=>{
	console.log(result); //Array of roomIds.
}).catch((err)=>{
	console.log(err);
});

DockerImage

dockerImgCreate

To Create a dockerimage for your project, Dockerimage will be created in your root directory.

var hacken = require('hacken');

var port = 3000; //port on which your node server will run.

var servfile = app.js; //your start file.

hacken.dockerImgCreate(port,servfile,(err)=>{
	if(err){
		console.log(err);
	}
	else{
		console.log("Docker File Created.");
	}
})

Socket Functions

For Now hacken only supports group chat.

socketFunction

To Create socket server, call the below function in your start file.

var hacken = require('hacken');

var app = require('express')();

var http = require('http');

var server = http.Server(app);

hacken.socketFunction(server);

server.listen(3000);