Can't read the url for URL shortener project

`var express = require(‘express’);
var app = express();

app.get(’/new/:url’, function(req, res){

app.listen(‘5000’, function(){
console.log(‘Server is on…’);

When I make a request to http://localhost:5000/new/test

It’s fine, it’s logging “test”

But when I http://localhost:5000/new/

It gives me nothing…

I search this forum and realise I have to put a “*” at the end of route like this…

app.get('/new/:url*', function(req, res){ console.log(req.originalUrl); })

Now when I make a request to http://localhost:5000/new/ it will log out new/ just fine. but I do not understand why putting an * will make it work. can anyone further explain this?


1 Like

Not really sure, but I suppose it has to do with the slashes in the url. My guess is that express “thinks” that everything after it is a subpath.