Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
maanimis committed Aug 27, 2024
1 parent a7d4761 commit 9767ea7
Show file tree
Hide file tree
Showing 14 changed files with 2,263 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
temp/

# Logs
logs
*.log
Expand Down
134 changes: 133 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,133 @@
# localCache

# localCache

### [Express.js In-Memory and Local Storage API](#expressjs-in-memory-and-local-storage-api)

This project is an Express.js API that provides endpoints to store, retrieve, and manage data in both in-memory storage and local storage (using the `node-localstorage` package). The API supports basic CRUD operations and is designed for simplicity and ease of use in development and testing environments.

## [Features](#features)

- **In-Memory Storage**: Store and retrieve data in memory, ideal for temporary storage during runtime.
- **Local Storage**: Store and manage data using `node-localstorage`, which saves data to the filesystem.
- **CORS Support**: Cross-Origin Resource Sharing (CORS) enabled for flexibility in development.
- **JSON API**: Interact with the API using JSON-formatted requests and responses.
- **Error Handling**: Comprehensive error handling for common scenarios (e.g., missing keys, not found).

## [Endpoints](#endpoints)

### [In-Memory Storage](#in-memory-storage)

- **Set Data in Memory**
```http
POST /memory/set
```
**Request Body:**
```json
{
"key": "yourKey",
"value": "yourValue"
}
```

- **Get Data from Memory**
```http
GET /memory/get/:keys
```
**URL Parameters:**
- `:keys` - Comma-separated list of keys to retrieve.

### [Local Storage](#local-storage)

- **Set Data in Local Storage**
```http
POST /local/set
```
**Request Body:**
```json
{
"key": "yourKey",
"value": "yourValue"
}
```

- **Get Data from Local Storage**
```http
GET /local/get/:keys
```
**URL Parameters:**
- `:keys` - Comma-separated list of keys to retrieve.

- **Remove Data from Local Storage**
```http
DELETE /local/remove/:keys
```
**URL Parameters:**
- `:keys` - Comma-separated list of keys to remove.

- **Clear Local Storage**
```http
DELETE /local/clear
```

## [Getting Started](#getting-started)

### [Prerequisites](#prerequisites)

- Node.js
- npm

### [Installation](#installation)

#### Method 1: Standard Installation

1. Clone the repository:
```bash
git clone https://github.com/maanimis/localCache
cd localCache
```

2. Install dependencies:
```bash
npm install
```

3. Create a configuration file `config/default.json` with the following structure:
```json
{
"api": {
"port": 3000,
"ip": "127.0.0.1"
},
"dbDir": "temp"
}
```

#### Method 2: Using `priv8-localcache`

+ Install the `priv8-localcache` package globally:
```bash
npm install -g priv8-localcache
```

### [Running the Server](#running-the-server)

Start the server using:
```bash
npm start
```

The server will be accessible at `http://127.0.0.1:3000`.

### [Testing the API](#testing-the-api)

You can use tools like [Postman](https://www.postman.com/) or `curl` to interact with the API.

Example using `curl`:
```bash
curl -X POST http://127.0.0.1:3000/memory/set -H "Content-Type: application/json" -d '{"key": "test", "value": "Hello, World!"}'
```

## [Contributing](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

9 changes: 9 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "default",
"dbDir": "temp",
"dbName": "requests.db",
"api": {
"ip": "0.0.0.0",
"port": 3000
}
}
7 changes: 7 additions & 0 deletions config/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "development",
"api": {
"ip": "127.0.0.1",
"port": 3000
}
}
7 changes: 7 additions & 0 deletions config/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "production",
"api": {
"ip": "0.0.0.0",
"port": 3000
}
}
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import globals from "globals";
import pluginJs from "@eslint/js";


export default [
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
];
Loading

0 comments on commit 9767ea7

Please sign in to comment.