Making a url shortener

is there a way to make an url shortener or at least any examples out there in glitch

1 Like

Sorry but I don’t get it

You convert the number ID to base62, you can use my module errors-base for that.

I am starting totally from scratch

and it doesn’t make sense

Server Code

const Base = require("errors-base").default;
const urls = [];
app.get("/:id", (req, res) => {
  const index = Base.decode(;
  if (!urls[id]) return res.status(404).end("404 not found");
app.put("/", (req, res) => {
  const index = urls.length;
  const id = Base.encode(index);
  res.set("Content-Type", "application/json");

Client Code:

Add URL:

const addURL = url => new Promise(async (resolve, reject) => fetch("/", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  body: JSON.stringify({ url })
}).then(response => response.json()).then(id => resolve(id)).catch(reject));


const id = await addURL("");
1 Like

So that’s all I do …

That should be a working URL-shortener, but it only saves in memory. You’d have to work on this to get it working properly.

1 Like

You can always opt for a pre-made option: