-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,263 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
temp/ | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "development", | ||
"api": { | ||
"ip": "127.0.0.1", | ||
"port": 3000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "production", | ||
"api": { | ||
"ip": "0.0.0.0", | ||
"port": 3000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; |
Oops, something went wrong.