Node-JS-Joke-API

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.

Setup

Prerequisites

Installation not needed use acidicts.hackclub.app with different requests

Installation

  1. Clone the repository:
    git clone https://github.com/Acidicts/Node-JS-Joke-API.git
    cd Node-JS-Joke-API
  2. Install dependencies:
    npm install
  3. Create a .env file in the root directory and set the environment variables:
    PORT=3000
    USER=<your-username>
    PWD=<your-password>
  4. Run the application:
    node index.js
  5. The server will be running on http://localhost:3000.

Endpoints

GET /

Serves the index.html file from the pub directory.

POST /add

Adds a new joke to the database.

GET /jokes

Retrieves all jokes from the database in HTML table format.

DELETE /reset

Deletes all jokes from the database.

DELETE /delete/:id

Deletes a joke by its ID.

GET /random

Retrieves a random joke from the database.

GET /joke/:id

Retrieves a joke by its ID.

Database

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:

Environment Variables

Static Files

Static files are served from the pub directory.

Running the Server

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.

License

This project is licensed under the MIT License.