{"id":23276236,"url":"https://github.com/dinoscapeprogramming/url-shortener-package","last_synced_at":"2025-04-06T11:45:01.174Z","repository":{"id":57987920,"uuid":"529310657","full_name":"DinoscapeProgramming/URL-Shortener-Package","owner":"DinoscapeProgramming","description":"A package you can use to create a URL Shorter","archived":false,"fork":false,"pushed_at":"2024-06-06T15:31:47.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-12T17:28:06.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DinoscapeProgramming.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-26T15:27:44.000Z","updated_at":"2024-06-06T15:31:51.000Z","dependencies_parsed_at":"2024-12-19T21:30:10.961Z","dependency_job_id":"097a9025-0920-4001-85b3-6f6bdfa1881b","html_url":"https://github.com/DinoscapeProgramming/URL-Shortener-Package","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"f135f5e8f254d08deeab9cdcec79ed62f463ef8c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FURL-Shortener-Package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FURL-Shortener-Package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FURL-Shortener-Package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DinoscapeProgramming%2FURL-Shortener-Package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DinoscapeProgramming","download_url":"https://codeload.github.com/DinoscapeProgramming/URL-Shortener-Package/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478251,"owners_count":20945262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-19T21:29:58.270Z","updated_at":"2025-04-06T11:45:01.152Z","avatar_url":"https://github.com/DinoscapeProgramming.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener Package\nA package you can use to create a URL Shortener with express\n\n## Installation progress\nThe package itself does not need any external packages, you only need packages when you try to execute the package\n\n## Features\n- Simple design\n- Advanced error logging\n\n## Create a database\nCreate a JSON File with an empty object\n```json\n{}\n```\n\n## Documentation\n### Setup\n```js\nconst express = require(\"express\"); // this package is express server based\nconst app = express();\nconst bodyParser = require(\"body-parser\");\nconst urlShortener = require('express-shortener');\n\napp.set('trust proxy', true); // required if you enabled \"logClicks\"\napp.use(bodyParser.json()); // required for post requests\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n```\n\n### Configuration\n```js\nurlShortener.configURL({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true // optional\n}).then((result) =\u003e {\n  console.log(\"Options were approved to the package\");\n});\n```\n\n### Open URL\n```js\napp.all(\"/url/:id\", (req, res) =\u003e {\n  urlShortener.openURL(req, res).then((result) =\u003e {});\n});\n```\n\n### Create URL\n```js\napp.all(\"/api/v1/url/create\", (req, res) =\u003e {\n  urlShortener.createURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n```\n\n### Edit URL\n```js\napp.all(\"/api/v1/url/edit\", (req, res) =\u003e {\n  urlShortener.editURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n```\n\n### Delete URL\n```js\napp.all(\"/api/v1/url/delete\", (req, res) =\u003e {\n  urlShortener.deleteURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n```\n\n### Get URL\n```js\napp.all(\"/api/v1/url/get\", (req, res) =\u003e {\n  urlShortener.getURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n```\n\n### Listen to Server\n```js\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n### Example\n```js\nconst express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst urlShortener = require('./urlShortener.js');\n\nurlShortener.configURL({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true\n}).then((result) =\u003e {\n  console.log(\"URL Shorter options were approved to the package\");\n});\n\napp.set('trust proxy', true);\napp.use(bodyParser.json());\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n\napp.all(\"/url/:id\", (req, res) =\u003e {\n  urlShortener.openURL(req, res).then((result) =\u003e {});\n});\n\napp.all(\"/api/v1/url/create\", (req, res) =\u003e {\n  urlShortener.createURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n\napp.all(\"/api/v1/url/edit\", (req, res) =\u003e {\n  urlShortener.editURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n\napp.all(\"/api/v1/url/delete\", (req, res) =\u003e {\n  urlShortener.deleteURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n\napp.all(\"/api/v1/url/get\", (req, res) =\u003e {\n  urlShortener.getURL(req.body).then((result) =\u003e {\n    res.json(result);\n  });\n});\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n## Class Documentation\n### Setup\n```js\nconst express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst urlShortener = require('express-shortener');\nconst Shortener = new urlShortener.Shortener({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true // optional\n});\n\napp.set('trust proxy', true); // required if you enabled \"logClicks\"\napp.use(bodyParser.json()); // required for post requests\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n```\n\n### Open URL\n```js\napp.all(\"/url/:id\", Shortener.open);\n```\n\n### Create URL\n```js\napp.all(\"/api/v1/url/create\", Shortener.create);\n```\n\n### Edit URL\n```js\napp.all(\"/api/v1/url/edit\", Shortener.edit);\n```\n\n### Delete URL\n```js\napp.all(\"/api/v1/url/delete\", Shortener.delete);\n```\n\n### Get URL\n```js\napp.all(\"/api/v1/url/get\", Shortener.get);\n```\n\n### Listen to Server\n```js\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n### Example\n```js\nconst express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst urlShortener = require('express-shortener');\nconst Shortener = new urlShortener.Shortener({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true\n});\n\napp.set('trust proxy', true);\napp.use(bodyParser.json());\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n\napp.all(\"/url/:id\", Shortener.open);\n\napp.all(\"/api/v1/url/create\", Shortener.create);\n\napp.all(\"/api/v1/url/edit\", Shortener.edit);\n\napp.all(\"/api/v1/url/delete\", Shortener.delete);\n\napp.all(\"/api/v1/url/get\", Shortener.get);\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n## Middleware Documentation\n### Setup\n```js\nconst express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst urlShortener = require('express-shortener');\n\napp.set('trust proxy', true);\napp.use(bodyParser.json());\napp.use(urlShortener.shortener({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true\n}));\n\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n```\n\n### Open URL\n```js\napp.all(\"/url/:id\", (req, res) =\u003e {\n  res.openURL();\n});\n```\n\n### Create URL\n```js\napp.all(\"/api/v1/url/create\", (req, res) =\u003e {\n  res.createURL();\n});\n```\n\n### Edit URL\n```js\napp.all(\"/api/v1/url/edit\", (req, res) =\u003e {\n  res.editURL();\n});\n```\n\n### Delete URL\n```js\napp.all(\"/api/v1/url/delete\", (req, res) =\u003e {\n  res.deleteURL();\n});\n```\n\n### Get URL\n```js\napp.all(\"/api/v1/url/get\", (req, res) =\u003e {\n  res.getURL();\n});\n```\n\n### Listen to Server\n```js\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n### Documentation\n```js\nconst express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst urlShortener = require('express-shortener');\n\napp.set('trust proxy', true);\napp.use(bodyParser.json());\napp.use(urlShortener.shortener({\n  file: \"./urls.json\",\n  parameter: \"id\",\n  logClicks: true\n}));\n\napp.use((req, res, next) =\u003e {\n  res.setHeader('X-Powered-By', 'Dinoscape');\n  next();\n});\n\napp.all(\"/url/:id\", (req, res) =\u003e {\n  res.openURL();\n});\n\napp.post('/api/v1/url/create', (req, res) =\u003e {\n  res.createURL();\n});\n\napp.post('/api/v1/url/edit', (req, res) =\u003e {\n  res.editURL();\n});\n\napp.post('/api/v1/url/delete', (req, res) =\u003e {\n  res.deleteURL();\n});\n\napp.post('/api/v1/url/get', (req, res) =\u003e {\n  res.getURL();\n});\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server is ready\");\n});\n```\n\n\n## Error Handling\n### Invalid options\nThe options you have given or not defined or not an object\n\n### No options were given\nYou have not executed the ConfigURL method before executing this method\n\n### No file was given\nYour options do not contain a file\n\n### Enable Trust Proxy\nYou set logClicks in the options to true but you have not enabled trust proxy\n```js\napp.set('trust proxy', true);\n```\n\n### No parameter was given\nYour options do not contain a but you have executed the openURL function so the package does not know what id it should open\n\n### Invalid parameter\nThe parameter does not exist in the request or is not defined\n\n### Id does not exist\nThe given id is not available in the database\n\n### No body was given\nThe body item was not given in the function\n\n### No url was given\nThe url item does not exist in the body\n\n### Invalid url\nThe url is not a valid\n\n### Id already exists\nThe custom id already exists in the database\n\n### No id was given\nThe id item does not exist in the body\n\n### No token was given\nThe token item does not exist in the body\n\n### Invalid token\nThe token is not valid\n\n### Other Errors\nOther errors are from the node internal packages fs and crypto (mostly fs when you enter a not existing file)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinoscapeprogramming%2Furl-shortener-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdinoscapeprogramming%2Furl-shortener-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinoscapeprogramming%2Furl-shortener-package/lists"}