Tell us what’s happening:
Hi everyone,
I’m stuck on the File Metadata Microservice project tests and I’m hoping someone can help figure out what I might be missing.
My API endpoint is working correctly when I manually upload a file. The response returns the expected JSON format with name, type, and size .
Example response:
{“name”:“localhost.sql”,“type”:“application/octet-stream”,“size”:304340}
My setup:
Node.js + Express
Multer for file uploads
Endpoint: POST /api/fileanalyse
Input field name: upfile
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Back-End Development and APIs Projects - File Metadata Microservice
look at the console in the browser and re-run the test to see what errors are being printed out
but working on normal browser upload
i can’t see the error. Please copy it here.
Error: blob is not implemented yet
at o (dom-test-evaluator.js:2:102733)
at Object.blob (dom-test-evaluator.js:2:103360)
at eval (eval at #a (dom-test-evaluator.js:2:255327), <anonymous>:6:31)
at async #a (dom-test-evaluator.js:2:255321)
at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:255829)
#a @ dom-test-evaluator.js:2
This looks like an fCC error to me. I don’t think it will get fixed so you should move on.
i think fCC shall fix these minor issues because clearing certification projects are necessary to obtain certificates.
They have said they will not fix it:
Out of curiosity, were you able to test the URL Shortener microservice?
nope, i am unable to pass 3rd test of that challenge, tried all possible values method but failed, i didn’t raise that issue because it was already widely discussed
I found this on GitHub:
opened 12:40AM - 21 Jan 26 UTC
closed 08:25AM - 13 Feb 26 UTC
scope: curriculum
status: waiting triage
archived coursework
### Describe the Issue
The URL Shortener Microservice behaves correctly when te… sted locally and fully complies with the project requirements. Valid URLs are successfully shortened, and accessing /api/shorturl/<short_url> consistently redirects to the original URL. Despite this, the freeCodeCamp test interface reports that not all unit and functional tests are passing. This issue cannot be reproduced in a local environment and appears to be related to differences in the automated testing environment rather than an error in the application logic.
### Affected Page
https://github.com/yirassssindaba-coder/URL-Shortener-Microservice
### Your code
```
index.js :
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const dns = require("dns");
const app = express();
// Basic Configuration
const port = process.env.PORT || 3000;
app.use(cors());
// FCC hint: body parsing middleware untuk POST
app.use(bodyParser.urlencoded({ extended: false }));
// (Opsional, aman) support JSON body juga
app.use(express.json());
// Static + homepage (sesuai template FCC)
app.use("/public", express.static(`${process.cwd()}/public`));
app.get("/", function (req, res) {
res.sendFile(process.cwd() + "/views/index.html");
});
/**
* In-memory "database"
* (FCC tests tidak mewajibkan database sungguhan)
*/
const urlDatabase = [];
let counter = 1;
function isValidHttpUrl(input) {
try {
const u = new URL(input);
return u.protocol === "http:" || u.protocol === "https:";
} catch (e) {
return false;
}
}
/**
* POST /api/shorturl
* Body: url=<some_url>
* Response: { original_url: 'https://...', short_url: 1 }
* Invalid: { error: 'invalid url' }
*/
app.post("/api/shorturl", (req, res) => {
const originalUrl = req.body.url;
// 1) Validasi format URL harus http(s)://
if (!isValidHttpUrl(originalUrl)) {
return res.json({ error: "invalid url" });
}
// 2) Validasi host lewat DNS lookup
const parsed = new URL(originalUrl);
const hostname = parsed.hostname;
dns.lookup(hostname, (err) => {
if (err) {
return res.json({ error: "invalid url" });
}
// Kalau sudah ada, balikin yang sama (stabil untuk test)
const existing = urlDatabase.find((x) => x.original_url === originalUrl);
if (existing) {
return res.json(existing);
}
const record = { original_url: originalUrl, short_url: counter++ };
urlDatabase.push(record);
return res.json(record);
});
});
/**
* GET /api/shorturl/:short_url
* Redirect ke original_url
*/
app.get("/api/shorturl/:short_url", (req, res) => {
const shortUrl = Number(req.params.short_url);
// jika param bukan angka, tetap aman
if (!Number.isInteger(shortUrl)) {
return res.json({ error: "invalid url" });
}
const found = urlDatabase.find((item) => item.short_url === shortUrl);
if (!found) {
return res.json({ error: "invalid url" });
}
// INI yang dinilai test #3: harus redirect ke URL asli
return res.redirect(found.original_url);
});
app.listen(port, function () {
console.log(`Listening on port ${port}`);
});
```
routes/api.js:
'use strict';
const dns = require('dns');
module.exports = function (app) {
// Simpan mapping di memory (cukup untuk FCC tests)
const urlDatabase = new Map(); // short_url -> original_url
let counter = 1;
const isValidHttpUrl = (input) => {
try {
const u = new URL(input);
return u.protocol === 'http:' || u.protocol === 'https:';
} catch {
return false;
}
};
app.post('/api/shorturl', (req, res) => {
const original_url = req.body && req.body.url;
// Harus format http://... atau https://...
if (!original_url || !isValidHttpUrl(original_url)) {
return res.json({ error: 'invalid url' });
}
const hostname = new URL(original_url).hostname;
// Verifikasi hostname dengan DNS lookup (sesuai hint FCC)
dns.lookup(hostname, (err) => {
if (err) {
return res.json({ error: 'invalid url' });
}
const short_url = counter++;
urlDatabase.set(String(short_url), original_url);
return res.json({
original_url,
short_url
});
});
});
app.get('/api/shorturl/:short_url', (req, res) => {
const short_url = req.params.short_url;
const original_url = urlDatabase.get(String(short_url));
if (!original_url) {
// FCC tidak minta format khusus untuk not found,
// tapi ini aman dan tidak mengganggu tests.
return res.status(404).json({ error: 'No short URL found for given input' });
}
return res.redirect(original_url);
});
};
### Expected behavior
When a valid URL is submitted via POST /api/shorturl, the API should return a JSON response containing both the original URL and a numeric short_url identifier. When visiting GET /api/shorturl/<short_url>, the server should respond with an HTTP redirect to the original URL. This behavior works consistently when tested locally and matches the project specifications exactly. Therefore, the freeCodeCamp test labeled “Failed: 3” should pass successfully.
### Screenshots
<img width="1913" height="900" alt="Image" src="https://github.com/user-attachments/assets/555bb6ba-8ed3-4b34-b330-e1cb233491ba" />
### System
- Device: [e.g. iPhone 6, Laptop]
- OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. 22]
### Additional context
_No response_
where this merge is mentioned:
main ← devin/1773746754-fix-dns-lookup-error
opened 11:26AM - 17 Mar 26 UTC
## Summary
Removes `dns.lookup()` entirely from the POST `/api/shorturl` endpoi… nt and replaces all URL validation with the `new URL()` constructor + an explicit protocol check (only `http:` and `https:` allowed). The previous approach — using `dns.lookup()` with an error callback — was causing valid URLs to be rejected in certain environments (notably the freeCodeCamp test runner), which caused test 3 to fail.
Reference: [freeCodeCamp issue #65378](https://github.com/freeCodeCamp/freeCodeCamp/issues/65378), [forum discussion](https://forum.freecodecamp.org/t/url-shortener-microservice-need-help/500763/6)
### Updates since last revision
- **Removed `dns.lookup` entirely** instead of just ignoring its error. The initial fix (ignoring the `err` parameter) was still failing test 3 in the freeCodeCamp test runner, likely due to DNS timeout/async issues.
- **Removed the regex** (`/^https?:\/\/.+/`). Validation is now done solely via `new URL()` (catches malformed URLs with a `TypeError`) and a protocol check (`urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:'`).
- **Removed the `dns` module import** since it is no longer used.
- This approach matches the solution from the freeCodeCamp forum that was confirmed to pass all tests.
## Review & Testing Checklist for Human
- [ ] **Run the freeCodeCamp test suite**: Submit the project URL to the [freeCodeCamp URL Shortener challenge](https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice) and verify all tests pass. This is the only definitive way to confirm the fix works.
- [ ] **Verify that invalid URLs are still rejected**: Test that submitting non-`http(s)` URLs (e.g., `ftp://example.com`, `example.com`, random strings) still returns `{ error: 'invalid url' }`.
- [ ] **Verify that valid URLs with unreachable/nonexistent hostnames are now accepted**: This is the intentional behavioral change — e.g., `http://nonexistent-domain-abc123.com` will now be stored rather than rejected. Confirm this is acceptable for your use case.
### Notes
- This repo has no automated tests or CI, so the only way to verify correctness is manual testing or through freeCodeCamp's test runner.
- Local smoke testing confirmed: valid URLs are accepted, `ftp://` URLs and random strings are rejected, redirect works correctly.
Link to Devin session: https://app.devin.ai/sessions/5518ee7598504fa1871643d4ee39be09
Requested by: @eraganiP
---
<a href="https://app.devin.ai/review/eraganip/urlshortener-microservice/pull/9" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin">
</picture>
</a>
I tried using this code, but I still had problems. If you want to try it or find something, let me know.
I also found this topic on the Forum where this was mentioned:
main ← a2937:feat/remove-methods-from-passed-objects
opened 10:07PM - 27 Feb 26 UTC
Checklist:
- [X] I have read [freeCodeCamp's contribution guidelines](htt… ps://contribute.freecodecamp.org).
- [X] My pull request has a [descriptive title](https://contribute.freecodecamp.org/#/how-to-open-a-pull-request?id=prepare-a-good-pr-title) (**not** a vague title like `Update index.md`)
Related to https://github.com/freeCodeCamp/freeCodeCamp/pull/66132
While it realistically will not that fix the issue; seeing as how a JSON stringified version of `URLSearchParams` will return an empty object, this could be pretty neat behavior for other objects being passed around in the future and help them be cloned.
But I didn’t understand how this could help in solving test 3.
alright, thanks for the follow, i will look into it tomorrow and let you know if i find it helpful
1 Like
do you have any news about it?
fCC does not plan to make any fixes to this archived course.
1 Like