Monday, January 30, 2023
how to earn money from adsterra.
const express = require("express");
const shortid = require("shortid");
const app = express();
const database = {};
app.get("/", (req, res) => {
res.send("Welcome to URL Shortener API");
});
app.get("/:url", (req, res) => {
const longUrl = req.params.url;
const shortUrl = shortid.generate();
database[shortUrl] = longUrl;
res.send(`Short URL: localhost:3000/${shortUrl}`);
});
app.get("/:shortUrl", (req, res) => {
const shortUrl = req.params.shortUrl;
const longUrl = database[shortUrl];
if (longUrl) {
res.redirect(longUrl);
} else {
res.send("URL not found");
}
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
Subscribe to:
Post Comments (Atom)
how to earn money from adsterra.
const express = require("express"); const shortid = require("shortid"); const app = express(); const database = {}; ap...
-
const express = require("express"); const shortid = require("shortid"); const app = express(); const database = {}; ap...
No comments:
Post a Comment