The Number Classification API is a simple Node.js and Express-based API that classifies numbers based on various mathematical properties. It determines whether a number is prime, perfect, Armstrong, even, or odd, and calculates the sum of its digits. Additionally, it fetches an interesting mathematical fact about the given number from the Numbers API.
- Classifies numbers based on:
- Prime status
- Perfect number status
- Armstrong number status
- Even or odd
- Calculates the sum of digits of the number
- Retrieves a fun mathematical fact from the Numbers API
- Handles CORS and JSON responses
- Node.js
- Express.js
- Axios
- CORS
Ensure you have Node.js installed on your system.
- Clone the repository:
git clone https://github.com/yourusername/number-classification-api.git cd number-classification-api - Install dependencies:
npm install
- Start the server:
The API will run at
npm start
http://localhost:3000(or the port specified inprocess.env.PORT).
Method: GET
Query Parameter:
| Parameter | Type | Description |
|---|---|---|
number |
Integer | The number to classify |
GET http://localhost:3000/api/classify-number?number=28
{
"number": 28,
"is_prime": false,
"is_perfect": true,
"properties": ["even"],
"digit_sum": 10,
"fun_fact": "28 is the second perfect number."
}number-classification-api/
│── node_modules/
│── utils.js
│── server.js
│── package.json
│── README.md
server.js: Main server file handling routes and API logic.utils.js: Utility functions for number classification and fetching fun facts.package.json: Project dependencies and scripts.README.md: Documentation.
You can deploy this API on cloud platforms like Heroku, Vercel, or Render.
To deploy manually on a server:
- Install Node.js on the server.
- Clone the repository.
- Run
npm install. - Use a process manager like PM2:
npm install -g pm2 pm2 start server.js --name number-api
This project is licensed under the MIT License.
Precious Akachukwu Nnorom
Contributions are welcome! Feel free to fork the repository and submit a pull request.
Happy coding! 🚀