Guides
Database Guide
Use Crescent.js's built-in database for create, read, update, and delete operations.
Overview
Crescent.js ships with an embedded database that requires no external setup. Create collections, insert records, query with filters, and update or delete data — all through the crescent.db API.
Zero configuration
The database is stored locally and works out of the box. No connection strings, no migrations, no ORM.
Creating Collections
create-collection.js
// Create a collection for users
crescent.db.create('users');
// Create a collection for products
crescent.db.create('products');Inserting Records
insert-records.js
crescent.db.insert('users', { name: 'Alice', email: 'alice@example.com' });
crescent.db.insert('users', { name: 'Bob', email: 'bob@example.com' });Reading Records
Retrieve all records or query with a filter object. Use find for every match and find_one for the first match.
read-records.js
// Get all users
const all = crescent.db.find('users');
// Get a specific user
const alice = crescent.db.find_one('users', { name: 'Alice' });
console.log(alice);Queries
Queries are plain objects:
{ name: "Alice" } matches every record where name equals "Alice". Omit the query to return all records.Updating Records
update-records.js
crescent.db.update(
'users',
{ name: 'Alice' },
{ email: 'alice@newdomain.com' }
);Deleting Records
delete-records.js
crescent.db.delete('users', { name: 'Bob' });Full Example
Here is a complete CRUD flow combined with an API endpoint:
db-api.js
// Create a users collection on startup
crescent.db.create('users');
const api = crescent.api_make({
api_id: 'main',
port: 3000
});
// GET /users - list all users
api.add_endpoint('GET', '/users', function (req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(crescent.db.find('users')));
});
// POST /users - create a user
api.add_endpoint('POST', '/users', function (req, res) {
crescent.db.insert('users', req.body);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ success: true }));
});
api.start();Next Steps
- Authentication Guide — secure your app with signup and login
- API Reference — every method in detail