So what’s happening from what I can tell is that when you call
api/shorturl/new you check to see if it exists and if it doesn’t you push the new url onto
urls which is your array.
But you never store that value anywhere permanent. The array only lives in memory and as soon as the script is done executing that data is gone. The next request that comes in will run the script again and you’ll recreate your
urls variable and initialize it to “https://www.gmail.com”.
Every time you send a request to
/api/shorturl/new the line:
let urls = ["https://www.gmail.com"] is ran.
This is why sending a request to
/api/shorturl/:url will never work because any url you try to add will never persist between requests.
This is where most people would use a database, but to answer your original question, no the project doesn’t require a database.
It doesn’t matter how you store the data so long as it lives somewhere that persists between requests to your server. You could write the data to a raw text file, or a json file if you want. But it needs to be stored somewhere that persists after the script is done executing and your script needs to be modified to read the data from wherever that storage is whether it’s a plain text file or a database.
Hope that helps to clarify all this!