Building Your First Project with Gwennel WebGwennel Web is a modern, lightweight web framework designed to help developers create fast, maintainable websites and web applications with minimal setup. This guide walks you through building your first project with Gwennel Web, covering installation, project structure, routing, templates, styling, data handling, and deployment. By the end you’ll have a small but complete web app you can expand.
Prerequisites
- Basic knowledge of HTML, CSS, and JavaScript
- Familiarity with Node.js (v14+) and npm or yarn
- A terminal/command line and a code editor (VS Code recommended)
1. Installing Gwennel Web
Start by creating a project directory and initializing a Node.js project:
mkdir gwennel-first-project cd gwennel-first-project npm init -y
Install Gwennel Web and a few helpful dev dependencies:
npm install gwennel-web npm install --save-dev nodemon
If Gwennel Web provides a CLI (replace with actual CLI command if different):
npx gwennel init
If the CLI scaffolds files, skip the manual scaffolding steps below. Otherwise, continue.
2. Project Structure
Create a simple structure:
- package.json
- server.js (or app.js)
- /routes
- index.js
- /views
- layout.html
- index.html
- /public
- /css
- styles.css
- /js
- main.js
- /css
This layout keeps server code, routes, templates, and static assets separated.
3. Basic Server and Routing
Create server.js to initialize Gwennel Web and define a route:
// server.js const Gwennel = require('gwennel-web'); const app = new Gwennel(); app.use(Gwennel.static('public')); // serve static files from /public app.get('/', (req, res) => { res.render('index', { title: 'Home — Gwennel Web Demo' }); }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));
If Gwennel uses a different API, adapt to its conventions (for example, app.router or Gwennel.createApp()).
4. Templates and Layouts
Gwennel Web supports HTML templates; here’s a simple layout and page.
views/layout.html:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>{{ title }}</title> <link rel="stylesheet" href="/css/styles.css" /> </head> <body> <header> <h1>Gwennel Web Demo</h1> </header> <main> {{{ body }}} </main> <footer> <p>© 2025 Gwennel Web Demo</p> </footer> <script src="/js/main.js"></script> </body> </html>
views/index.html:
<section> <h2>Welcome to Gwennel Web</h2> <p>This is your first project. Use the template engine’s interpolation to display dynamic data.</p> <p>Title: <strong>{{ title }}</strong></p> <a href="/about">About</a> </section>
Adjust template tags to match Gwennel’s templating syntax (e.g., {{ }}, {{{ }}}).
5. Static Assets and Styling
public/css/styles.css:
:root { --bg: #f7fafc; --primary: #2b6cb0; --muted: #4a5568; } body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial; background: var(--bg); color: var(--muted); margin: 0; padding: 0; } header { background: var(--primary); color: white; padding: 1rem; } main { max-width: 800px; margin: 2rem auto; padding: 1rem; background: white; border-radius: 8px; box-shadow: 0 4px 14px rgba(43,108,176,0.08); }
public/js/main.js:
document.addEventListener('DOMContentLoaded', () => { console.log('Gwennel Web demo loaded'); });
6. Adding an About Page and Navigation
routes/index.js:
module.exports = (app) => { app.get('/', (req, res) => res.render('index', { title: 'Home — Gwennel Web Demo' })); app.get('/about', (req, res) => res.render('about', { title: 'About — Gwennel Web Demo' })); };
views/about.html:
<section> <h2>About Gwennel Web</h2> <p>Gwennel Web is built for simplicity and performance. This demo shows routing, templates, and static assets.</p> <a href="/">Home</a> </section>
Import routes in server.js if needed:
const routes = require('./routes/index'); routes(app);
7. Handling Form Data and Simple API
Add a contact form to index.html:
<form id="contact" method="POST" action="/contact"> <label>Name <input name="name" required></label> <label>Message <textarea name="message" required></textarea></label> <button type="submit">Send</button> </form>
Server-side handler in server.js:
app.use(Gwennel.urlencoded()); // parse form data app.post('/contact', (req, res) => { const { name, message } = req.body; // In a real app, validate and store/send the message res.render('contact-success', { title: 'Message Sent', name }); });
views/contact-success.html:
<section> <h2>Thanks, {{ name }}!</h2> <p>Your message was received.</p> <a href="/">Back</a> </section>
8. Data Persistence (Optional)
For simple projects, use a JSON file or low-footprint DB like SQLite or lowdb.
Example using lowdb:
npm install lowdb
const { Low, JSONFile } = require('lowdb'); const db = new Low(new JSONFile('./data/db.json')); await db.read(); db.data ||= { messages: [] }; app.post('/contact', async (req, res) => { const { name, message } = req.body; db.data.messages.push({ id: Date.now(), name, message }); await db.write(); res.render('contact-success', { title: 'Message Sent', name }); });
9. Development Workflow
Add scripts to package.json:
"scripts": { "dev": "nodemon server.js", "start": "node server.js" }
Run:
npm run dev
10. Deployment
- For simple Node.js apps, deploy to platforms like Vercel, Render, Fly.io, or a VPS.
- Ensure environment variables (PORT, NODE_ENV) are handled.
- Build any static optimizations and set appropriate process manager (PM2) if using a VPS.
Next Steps and Tips
- Add user authentication if needed (JWT or sessions).
- Introduce client-side interactivity with a small frontend framework (Alpine.js, Vue, or React).
- Write tests for routes and API endpoints.
- Optimize assets (minify CSS/JS, use compression).
This gives you a complete path from installation to deployment for a small Gwennel Web app. Adapt template syntax and API calls to match the actual Gwennel Web APIs you have available.
Leave a Reply