This is a simple Node.js API server that process image using JSON Web Tokens (JWT) for authentication. The server is built using the famous Sharp
library and Nodejs-API-Authentication.
- Process Image:
- Apply any
Sharp
image processing operation to an image.
- Apply any
- Sharp: High-performance image processing library for Node.js (link).
- qs: Library for parsing query strings in URLs (link).
- Nodejs-API-Authentication: A simple Node.js API server with JWT authentication (link).
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Install dependencies:
npm install or yarn install
-
Set up the SQLite database:
- The application will automatically create a database file (
database.sqlite
) in the project root directory when the server starts. You can configure your database connection settings in theconfig/database.js
file if needed.
- The application will automatically create a database file (
-
Create a
.env
file at the root of your project for environment variables:JWT_SECRET=<your_jwt_secret_key> PORT=3000
You must include the JWT token in the Authorization
header for all requests. The token is generated when you log in to the server.
- Process an image using
Sharp
and return the processed image. - Body:
{ "url": "https://example.com/image.jpg", "format": "png", "background": "#ff0000", "resize": { "width": 300, "height": 300, "fit": "contain", }, }
- Response:
<processed_image>
- Process an image using
Sharp
and return the processed image. - Body:
Query:
{ }
"url=https://example.com/image.jpg&format=png&background=#ff0000&resize[width]=300&resize[height]=300&resize[fit]=contain"
- Response:
<processed_image>
The server uses winston for logging and debug with @colors/colors for debugging. You can enable debug logs by setting the environment variable DEBUG=*
and specifying a log level for winston
.
-
Register a user:
curl -X POST http://localhost:4000/users/register -H "Content-Type: application/json" -d '{"email": "user@example.com", "password": "password123", "username": "user123"}'
-
Log in to get the JWT token:
curl -X POST http://localhost:4000/users/login -H "Content-Type: application/json" -d '{"username": "user123", "password": "password123"}'
-
Process an image:
curl -X GET http://localhost:4000/image?url=https://[....].png&toFormat=jpg&resize%5Bwidth%5D=300' -H "Authorization: Bearer <jwt_token>"
for more information, please check the image.sh file.
This project is licensed under the MIT License - see the LICENSE file for details.