Skip to content

44vibe/nodejs-coder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temperature Converter API Challenge

Your Task

Build an Express.js API that converts Celsius to Fahrenheit.

Requirements

Endpoint

  • Route: GET /convert
  • Query Parameter: celsius (number)
  • Returns: JSON with both temperatures

Example Request

GET /convert?celsius=25

Example Response

{
  "celsius": 25,
  "fahrenheit": 77
}

Error Handling

Return proper error for:

  • Missing celsius parameter
  • Invalid input (not a number)

Error Response Example

{
  "error": "Invalid input: celsius must be a number"
}

Getting Started

  1. Open server.js
  2. Find the TODO sections
  3. Implement the conversion logic
  4. Test your API

Running Your Server

node server.js

Server runs on port 3000.

Testing

# Test valid request
curl "http://localhost:3000/convert?celsius=0"

# Test invalid request
curl "http://localhost:3000/convert?celsius=abc"

# Or run automated tests
node test.js

Formula

Fahrenheit = (Celsius × 9/5) + 32

Tips

  • Check if celsius query parameter exists
  • Validate it's a number using isNaN()
  • Use parseFloat() to convert string to number
  • Round to 2 decimal places

Good luck! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors