0.0.5 • Published 4 years ago
node-link-shortner v0.0.5
node-link-shortner
A link shortner with analytics built in node with a frontend built with EJS.
Setup
Set the CONFIG_FILE_NAME
variable in .env
to a path of your choice. If you leave it blank it will be created to ./config.json
Steps:
- Run your program once. It will exit out after creating the config file.
- Update the config file with the correct details.
- Run the program again. This time it will run successfully.
Example Config:
{
"mongo": {
"host": "0.0.0.0",
"port": "8080",
"database": "example",
"username": "example",
"password": "example"
},
"web": {
"enabled": true,
"port": 8080,
"host": "0.0.0.0",
"authentication": {
"_comment": "coming soon"
}
},
"database": "mongo"
}
Example Usage:
const linkStorage = require('node-link-shortner')
// Outputs the new link:
/*
{
link: 'exampleLink',
redirect: 'https://google.com',
stats: {
uniqueHits: 0,
totalHits: 0,
sourceHits: {}
}
}
*/
linkStorage.addLink('https://google.com').then(link => { /* Do stuff */ })
/**
* IF WEB IS ENABLED, THIS WILL MAKE => host:port/linkName redirect to the desired link.
* /
// Outputs the removed link:
/*
{
link: 'exampleLink',
redirect: 'https://google.com',
stats: {
uniqueHits: 0,
totalHits: 0,
sourceHits: {}
}
}
*/
linkStorage.removeLink('exampleLink').then(link => { /* Do stuff */ })
// Outputs the removed link:
/*
{
uniqueHits: 0,
totalHits: 0,
sourceHits: {}
}
*/
linkStorage.getLinkStats('exampleLink').then(link => { /* Do stuff */ })
// Outputs the removed link:
/*
[
{
link: 'exampleLinkOne',
redirect: 'https://google.com',
stats: {
uniqueHits: 0,
totalHits: 0,
sourceHits: {}
}
},
{
link: 'exampleLinkTwo',
redirect: 'https://google.com',
stats: {
uniqueHits: 0,
totalHits: 0,
sourceHits: {}
}
},
]
*/
linkStorage.getAllLinks('exampleLink').then(link => { /* Do stuff */ })
Contributing
I'm leaving it up to the community to contibute extra database support. As of currently this will only support Mongo
You will be credited here for your contibutions:
- MongoDB -- @Luke-6723