-
Notifications
You must be signed in to change notification settings - Fork 1
Using Handler Or Pages
Shodiqul Muzaki edited this page Mar 12, 2016
·
3 revisions
if you want to add new page in CermaiJS you just add file on directory routes example code and i named with newpage.js
function NewPage(db) {
this.index = function(req,res,next) {
res.send("Hellow This is new page of CermaiJS");
}
}
module.exports = NewPage;
- db : if you want to use database
- req : to handle request from HTTP Server
- res : to handle respone from HTTP Server
- res.send : output with 1 line
- res.json : output json format
- res.render : render template jade (default cermai)
- module.exports : that can be called with require
open and edit file routes.js on root directory add new code example
var NewPageHandler = require('./routes/newpage');
var NewPage = new NewPageHandler(db);
cermai.get('/newpage', NewPage.index);
- cermai : is server in cermaijs
- get : method url get
- post : method url post
- delete : method url delete (maybe not used on cermaijs)
to test it's work or not you can open your website with page /newpage with get method
Support By Syntax Blog