The Node-JS-Joke-API is an Express-based web application that allows users to manage a collection of jokes stored in a SQLite database. The API supports adding, retrieving, deleting, and resetting jokes.
git clone https://github.com/Acidicts/Node-JS-Joke-API.git
cd Node-JS-Joke-API
npm install
.env file in the root directory and set the environment variables:
PORT=3000
USER=<your-username>
PWD=<your-password>
node index.js
http://localhost:3000.Serves the index.html file from the pub directory.
Adds a new joke to the database.
joke (string, required): The joke text.201 Created: Returns the ID and joke text of the newly added joke.400 Bad Request: Joke is required.500 Internal Server Error: Error message.Retrieves all jokes from the database in HTML table format.
200 OK: Returns the HTML table with all jokes.500 Internal Server Error: Error message.Deletes all jokes from the database.
user (string, required): Username.pwd (string, required): Password.204 No Content: Jokes deleted.401 Unauthorized: Incorrect username or password.500 Internal Server Error: Error message.Deletes a joke by its ID.
id (integer, required): The ID of the joke to delete.204 No Content: Joke deleted.400 Bad Request: ID is required.500 Internal Server Error: Error message.Retrieves a random joke from the database.
200 OK: Returns a random joke.500 Internal Server Error: Error message.Retrieves a joke by its ID.
id (integer, required): The ID of the joke to retrieve.200 OK: Returns the joke text.400 Bad Request: ID is required.404 Not Found: Joke not found.500 Internal Server Error: Error message.The application uses SQLite3 for database management. The database file is named database.db and is created in the root directory if it does not exist. The jokes table contains the following columns:
id (INTEGER, PRIMARY KEY, AUTOINCREMENT): The unique identifier for each joke.joke (TEXT, NOT NULL): The joke text.PORT: The port on which the server will run. Default is 3000.USER: The username for resetting the jokes.PWD: The password for resetting the jokes.Static files are served from the pub directory.
To start the server, run:
node index.js
The server will be running on the port specified in the .env file or default to 3000.
This project is licensed under the MIT License.