0
How to write a function to shorten a URL using JavaScript?
7 odpowiedzi
+ 2
You need server script eg. PHP for url redirection.
+ 1
Front-end JavaScript cannot run from server side, it run from device browsers. Unless you refer to Node.js.
+ 1
Assume you use Nodejs with Express and MongoDb database with modal UrlShorten.
The part to shortening url could be:
const mongoose = require("mongoose");
const UrlShorten = mongoose.model("UrlShorten");
module.exports = app => {
//GET API for redirecting to Original URL
app.get("/api/item/:code", async (req, res) => {
});
//POST API for creating short url from Original URL
app.post("/api/item", async (req, res) => { });
};
More detail information please visit https://codeburst.io/creating-custom-url-shortener-with-nodejs-de10bbbb89c7
0
JavaScript function need
0
Javascript cannot perform server function.
0
but JavaScript can use for server side also
0
assume refer to Nodejs then what about function