📚 StoneJS Developer Guide
Complete reference for building modern web applications with the StoneJS Framework
🚀 Quick Start
Installation
Clone the repository and install dependencies:
git clone https://github.com/yourorg/stonejs-framework.git
cd stonejs-framework
npm install
Configuration
Create a .env file for your database and session configuration:
# Database Configuration
DB_TYPE=postgresql
DB_HOST=localhost
DB_PORT=5432
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
# Session Configuration
SESSION_SECRET=your-secret-key-change-in-production
SESSION_STORE=database
# Optional: Separate session database
SESSION_DB_HOST=localhost
SESSION_DB_PORT=5432
SESSION_DB_USER=session_user
SESSION_DB_PASSWORD=session_password
SESSION_DB_NAME=sessions
Start the Server
npm start
# Server runs on http://localhost:3000
Your First Page
Create a file at pages/hello.html:
<%%js>
// This runs on every request
$context.set('title', 'Hello World');
const name = $req.query.name || 'World';
<h1>Hello, <%= name %>!</h1>
<p>Visit <code>/hello.html?name=YourName</code> to personalize this greeting.</p>
Visit http://localhost:3000/hello.html to see your page!
Your First Component
Create a reusable component at pages/components/greeting.html:
<%%js>
// Component receives props from include()
const name = $context.get('name') || 'Guest';
const message = $context.get('message') || 'Welcome!';
<div style="border: 2px solid #667eea; padding: 1rem; border-radius: 8px;">
<h3>👋 Hello, <%= name %></h3>
<p><%= message </p>
</div>
Use it in any page:
<%%js>
$context.set('name', 'Alice');
$context.set('message', 'Welcome to StoneJS!');
<%- await include('components/greeting') %>
Your First API Endpoint
Create a dhandler at pages/api/hello/dhandler:
module.exports = async (context) => {
const { req, res } = context;
if (req.method === 'GET') {
return res.json({
message: 'Hello from the API!',
timestamp: new Date().toISOString()
});
}
return res.status(405).json({ error: 'Method not allowed' });
};
Test it: http://localhost:3000/api/hello
Next Steps
Need more help?