Skip to content

Latest commit

 

History

History
133 lines (100 loc) · 1.9 KB

File metadata and controls

133 lines (100 loc) · 1.9 KB

nodeMemoryDB

简体中文 | English

A simple in-memory database service built with Node.js.

Requirements

  • Node.js >= 14.0.0
  • npm >= 6.0.0

Features

  • Lightweight in-memory database
  • RESTful API interface
  • Easy to use
  • Basic CRUD operations support

Installation

npm install nodeMemoryDB

Usage

Start the server:

npm run start

The server will start on port 81 and run as a memory database service.

API Endpoints

Data Operations

Get Data

  • GET /get
    • Parameters:
      • key: (Optional) Key name. Returns all data if not provided
      • meta: (Optional) Set to 1 to return metadata

Request examples:

# Get data for specific key
curl http://localhost:81/get?key=abc

# Get data with metadata
curl http://localhost:81/get?key=abc&meta=1

# Get all data
curl http://localhost:81/get

Response example:

{
  "message": "get abc success",
  "data": "123"
}

Set Data

  • GET/POST /set
    • Parameters:
      • key: Key name
      • value: Value to store

Request examples:

# Using GET
curl "http://localhost:81/set?key=abc&value=123"

# Using POST
curl -X POST http://localhost:81/set \
  -H "Content-Type: application/json" \
  -d '{"key": "abc", "value": "123"}'

Response example:

{
  "message": "abc is stored",
  "data": "success"
}

Delete Data

  • GET/POST /del
    • Parameters:
      • key: Key name to delete

Request example:

curl "http://localhost:81/del?key=abc"

Response example:

{
  "message": "abc is deleted",
  "data": "success"
}

Clear Database

  • GET/POST /clear
    • Note: Only accessible from localhost (127.0.0.1)

Request example:

curl http://localhost:81/clear

Response example:

{
  "message": "DB is cleared",
  "data": "success"
}

Dependencies

  • express: ^4.17.1
  • body-parser: ^1.19.0
  • cors: ^2.8.5

License

MIT