- JavaScript 100%
TaskFlow API #
TaskFlow is a Node.js + Express backend that currently focuses on user authentication. It demonstrates secure credential storage, JSON Web Token (JWT) based sessions, and a lightweight file-backed data store that keeps user information between restarts.
Features #
- User registration with server-side validation.
- Secure password hashing using
bcryptjs. - JWT issuance on login for stateless authentication.
- File-backed user store that persists credentials across restarts.
- Automated integration tests covering the authentication flow.
Prerequisites #
- Node.js v18 or newer.
Getting Started #
- Install dependencies:
npm install - Create a
.envfile (optional) to override defaults:PORT=5000 JWT_SECRET=choose-a-long-random-string USER_DATA_FILE=./data/users.jsonJWT_SECRETshould always be set to a strong random value in production.USER_DATA_FILEcan point to any writable path if you want to isolate data per environment.
- Start the API:
npm start - The service listens on
http://localhost:5000by default. A health check is available at/.
Authentication API #
All routes expect and return JSON.
POST /auth/register #
Registers a new user.
Request body:
{
"username": "demo-user",
"password": "super-secret-password"
}
Validation rules:
usernameandpasswordare required.- Passwords must be at least 8 characters long.
- Usernames must be unique.
Responses:
201 Createdon success.400 Bad Requestwhen validation fails.409 Conflictwhen the username already exists.
POST /auth/login #
Authenticates a user and returns a JWT access token.
Request body matches the registration format.
Responses:
200 OKwith{ message, token, expiresIn }when the credentials are correct.400 Bad Requestfor validation errors.401 Unauthorizedwhen the credentials do not match a known user.
Include the returned token as a Bearer token in the Authorization header to protect future endpoints.
Testing #
Run the automated test suite with:
npm test
The tests use an isolated temporary data file so they do not interfere with local development data.
Project Structure #
├── auth.js # Authentication routes
├── index.js # Express application entry point
├── lib/
│ └── userStore.js # File-backed user persistence
├── data/
│ └── README.md # Notes about the file-backed datastore location
├── __tests__/
│ └── auth.test.js # Integration tests for the auth flow
└── README.md
Next Steps #
- Add role-based access control and protected routes for future task management features.
- Replace the file data store with a production-ready database (PostgreSQL, MongoDB, etc.).
- Implement task CRUD endpoints that leverage authenticated user context.
- Extend the test suite with negative cases, token verification, and future domain logic.
License #
This project is licensed under the MIT License. See LICENSE for more information.