Not Passing URL Shortener Microservice Project Test

Tell us what’s happening:
I cannot pass the URL Shortener Microservice. I tried my project and it can response with JSON with original_url and short_url properties & redirect it to the original URL as required. So I’m not sure why I cannot pass it… hope others’ insight could help ><
Is it necessary to use Mongoose? I didn’t use mongoose in the project though…
Thank you for any help :’(

Your code so far
project link:
code link:


const express = require('express');
const cors = require('cors');
const app = express();
const dns = require('dns');
const bodyParser = require('body-parser');

// Basic Configuration
const port = process.env.PORT || 3000;


app.use('/public', express.static(`${process.cwd()}/public`));

app.use(bodyParser.urlencoded({ extended: false }));

app.get('/', function(req, res) {
  res.sendFile(process.cwd() + '/views/index.html');

const links = [];
let id = 0;

// Your first API endpoint'/api/shorturl/new', function(req, res) {
  const { url } = req.body;
  const noHTTPSurl = url.replace(/^https?:\/\//, '');

  dns.lookup(noHTTPSurl, (err) => {
    if(err) {
      return res.json({
        "error": "invalid URL"
    } else {
      const link = {
        original_url: url,
        short_url: `${id}`
      return res.json(link);

app.get('/api/shorturl/:id', (req, res) => {
  const { id } = req.params;
  const link = links.find(a => a.short_url === id);
  if(link) {
    return res.redirect(link.original_url);
  } else {
    return res.json({
      error: 'No short url'


app.listen(port, function() {
  console.log(`Listening on port ${port}`);

Your browser information:

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

Challenge: URL Shortener Microservice

Link to the challenge:

Which tests in particular are failing? When I get stuck on these projects with backend, I always find it is helpful to see how fCC runs their tests and check my code in comparison. For this particular project, you can find the tests here:

Thanks for your help.
I am failing in these two tests:
2. You can POST a URL to /api/shorturl/new and get a JSON response with original_url and short_url properties. Here’s an example: { original_url : '', short_url : 1}
3. When you visit /api/shorturl/<short_url> , you will be redirected to the original URL.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Also, I believe this has to do with the dns library:

Hope this helps

Thanks, i passed it xD