Back End Development and APIs Projects - URL Shortener Microservice

Passes test 1 and 4 but not 2 and 3. Functionality seems to be the same as the example. Unsure exactly what is incorrect.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Back End Development and APIs Projects - URL Shortener Microservice

Link to the challenge:

1 Like
  1. Typo in body-parser module import: The bodParse variable is a typo and should be bodyParser.
const bodyParser = require('body-parser');

Missing let keyword when declaring newURL variable:'/api/shorturl', (req, res) => {
  let url = req.body.url.replace(/^https?:\/\//, '');
  url = url.replace(/\/$/, '');
  let domain = url.split('/')[0];
  dns.lookup(domain, (err, address, family) => {
    if (err || !address) {
      res.json({error: 'invalid url'});
    } else {
      let newURL = { original_url: req.body.url, short_url: urls.length};

app.get('/api/shorturl/:short_url?', (req, res) => {
  let short_url = req.params.short_url;
  let entry = urls.find(obj => obj.short_url == short_url);
  if (entry) {
    let long_url = entry['original_url'];
    if (long_url) {
    } else {
      res.json({error: 'not found'});
  } else {
    res.json({ error: 'not found'});

app.listen(port, function() {
  console.log(`Listening on port ${port}`);
I hope this helps!

AFAIK it doesn’t really matter what variable you set your module imports to as long as you are consistent within your code?

Otherwise, I did fix the missing let keyword, and everything (still) seems to function exactly as in the example, but my tests aren’t passing.

I think I will just move on from this section of the curriculum at this point as I have been stuck here spinning my wheels for days and I won’t be able to get the back end certification until I get this to pass. Maybe I will be able to fix it in the future. Thanks for the help anyways!

1 Like

I’ll take another look, if I can help you.
I have some free time, a few more days. Just to rest my brain from Sudoku Solver

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.