Very sime plen nodeejs database.
Copy either racco.js
or racco.ts
straight into your project folder, depending on if you use javascript or typescript.
You must then set the DATA_DIR
variable at the top to the path to the folder which will contain the data, relative to the racco.js
file.
The Datastore
class takes a string of the name, and a function which returns the initial data. Then, it returns an instance with a property called data
.
This is your data, and you can change it just like a regular javascript value.
When you change it, it is automatically persisted to disk and loaded the next time you start your server.
// data.js ->
const { Datastore } = require("./racco");
exports.people = new Datastore("people", () => new Map());
// yourcode.js
const { people } = require("./data");
exports.signup = (username, password) => {
people.data.set(username, { password });
}
exports.checkPassword = (username, password) {
return people.data.get(username).password === password;
}
The name is elijah's fault.