
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
The **jsonDB** library provides an easy way to work with JSON data as a database.
The jsonDBKit library provides an easy way to work with JSON data as a database.
jsonDB.connectDB(path: string): Promise<void>
jsonID) generated with uuid for the first object in the collections if it doesn't exist yet. jsonDB.jsonGetAllCollections(): Promise<object>
jsonDB.jsonGetCollection(collectionName: string): Promise<object[]>
jsonDB.jsonGetOne(collectionName: string, id: string): Promise<object | undefined>
jsonDB.jsonAdd(collectionName: string, content: object): Promise<object>
jsonDB.jsonFoundOneAndUpdate(collectionName: string, id: string, obj: object): Promise<object | undefined>
jsonDB.jsonDelete(collectionName: string, id: string): Promise<number | undefined> Promise<object | undefined>
To install the jsondbkit library, run the following command:
npm install --save jsondbkit
Create folder for your database:

Create JSON file inside your folder:

Important!:
To work successfully with the database, you need to create a schema of your database inside your JSON file.
Example of your schema:
{
"users": [
{
"fullname": "John Doe",
"age": 30,
"phone": "xxxxxxxxxx"
}
],
"products": [
{
"productName": "Phone"
}
]
}
Important Notes!:
The object must contain a field - collection (in this example, collections are represented by "products" and "users"). There can be as many collections as desired (the only drawback is that they need to be entered manually at the moment).
The collection must be an array.
The array must contain objects.
Note: For proper operation, each collection must contain exactly one object before working with the database
The object should not contain the jsonID property. After running, unique identifiers will be added to each object in each collection in the database.

After following all instructions and running the application, your JSON file will be automatically overwritten. If you use Nodemon, all subsequent changes (additions, deletions, edits) will occur automatically, overwriting your file with new data, while preserving the entire order.
Create Express Server:
const express = require('express');
const app = express();
const usersRouter = require('./routes/usersRouter');
const connectToJsonDB = require('./configs/connectToJsonDB');
const PORT = 3000;
//configs
connectToJsonDB();
//MIDDLEWARES
app.use(express.json());
//ROUTES
app.use('/api/users', usersRouter);
//LISTEN
app.listen(PORT, () => {
console.log(`Server is running: http://localhost:${PORT}`);
});
Create your connect methood:
I moved the function to a separate file:
const jsonDB = require('jsondbkit');
const connectToJsonDB = () => {
jsonDB.connectDB('./DB/test.json')
.then(() => console.log('DB is OK'))
.catch((err) => console.log(err));
}
module.exports = connectToJsonDB;
Create routes folder:

In this example i will show only on "users" collection(for other collections, everything is absolutely identical)
All routes for users:
const express = require('express');
const router = express.Router();
const usersDLL = require('../DLL/usersDLL');
router.get('/', async(req, res) => {
const response = await usersDLL.getAllUsers();
res.send(response);
});
router.get('/:id', async(req, res) => {
const id = req.params.id;
const response = await usersDLL.getOneUser(id);
res.send(response);
});
router.post('/', async(req, res) => {
const obj = req.body;
const response = await usersDLL.addNewUser(obj);
res.send(response);
});
router.put('/:id', async(req, res) => {
const id = req.params.id;
const obj = req.body;
const response = await usersDLL.updateUser(id, obj);
res.send(response);
});
router.delete('/:id', async(req, res) => {
const id = req.params.id;
const response = await usersDLL.deleteUser(id);
res.send(response);
});
module.exports = router;
Let's move all CRUD methods to a separate folder

const jsonDB = require('jsondbkit');
const getAllUsers = async () => {
return jsonDB.jsonGetCollection("users");
}
const getOneUser = async (id) => {
return await jsonDB.jsonGetOne("users", id);
}
const addNewUser = async (obj) => {
await jsonDB.jsonAdd("users", obj);
return 'User addded succesfully';
}
const updateUser = async (id, obj) => {
await jsonDB.jsonFoundOneAndUpdate("users", id, obj);
return 'User updated succesfully';
}
const deleteUser = async (id) => {
let response = await jsonDB.jsonDelete("users", id);
if (!response) {
return 'Not found';
}
return 'User deleted succesfully';
}
module.exports = {
getAllUsers,
getOneUser,
addNewUser,
updateUser,
deleteUser
}
Let's check with Postman:
getAllUsers

getOneUser

addNewUser

Result in json:

updateUser

Result in json:

deleteUser

Result in json:

FAQs
The **jsonDB** library provides an easy way to work with JSON data as a database.
We found that jsondbkit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.