API Reference v9.3.4
Complete documentation of all methods and properties available in Novaxjs2 version 9.3.4.
Core Methods
| Method | Description | Example |
|---|---|---|
get(path, ...handlers) | Define GET route with optional middleware | app.get('/', authMiddleware, (req, res) => {...}) |
post(path, ...handlers) | Define POST route with optional middleware | app.post('/users', validateUser, (req, res) => {...}) |
put(path, ...handlers) | Define PUT route with optional middleware | app.put('/users/:id', authMiddleware, (req, res) => {...}) |
delete(path, ...handlers) | Define DELETE route with optional middleware | app.delete('/users/:id', authMiddleware, (req, res) => {...}) |
group(prefix, callback) | Group routes under a common prefix | app.group('/api', ({ get, post }) => { |
at(port, host, callback) | Start server on specified port | app.at(3000, 'localhost', () => {...}) |
on(status, handler) | Custom error handler for specific status codes | app.on(404, () => 'Not found') |
init(options) | Initialize app with configuration options | app.init({ staticPath: 'public', minifier: true }) |
useRouter(router) | Use a router module or function | app.useRouter(userRouter); |
Middleware Methods
| Method | Description | Example |
|---|---|---|
useMiddleware(fn) | Add standard middleware | app.useMiddleware((req, res, next) => {...}) |
useErrorMiddleware(fn) | Add error middleware | app.useErrorMiddleware((err, req, res, next) => {...}) |
serveStatic(dir) | Serve static files from directory | app.serveStatic('public') |
Configuration Methods
| Method | Description | Example |
|---|---|---|
cors(options) | Configure CORS settings | app.cors({ origins: ['*'] }) |
setFileSizeLimit(mb) | Set file upload size limit | app.setFileSizeLimit(50) |
setFileConfig(config) | Configure multiple file upload settings | app.setFileConfig({ maxSize: 10, allowedTypes: ['image/*'] }) |
setAllowedFileTypes(types) | Set allowed MIME types for uploads | app.setAllowedFileTypes(['image/jpeg', 'image/png']) |
setMaxFiles(max) | Set maximum number of files per upload | app.setMaxFiles(5) |
setKeepOriginalName(keep) | Set whether to keep original filenames | app.setKeepOriginalName(true) |
style(css) | Set global CSS styles | app.style = 'body { color: red }' |
js(script) | Set global JavaScript | app.js = 'console.log("Hello")' |
Request Object
| Property | Description | Type |
|---|---|---|
req.method | HTTP method (GET, POST, etc.) | String |
req.url | Request URL | String |
req.query | Parsed query parameters | Object |
req.params | Route parameters | Object |
req.body | Parsed request body | Object |
req.files | Uploaded files | Object |
req.protocol | Request protocol (http/https) | String |
req.fullUrl | Complete request URL | String |
req.ip | Client IP address | String |
req.headers | Request headers | Object |
req.cookies | Parsed cookies | Object |
Response Methods
| Method | Description | Example |
|---|---|---|
res.status(code) | Set HTTP status code | res.status(404) |
res.json(data) | Send JSON response | res.json({ success: true }) |
res.redirect(url) | Redirect to URL | res.redirect('/home') |
res.send(content, contentType) | Send raw content with optional content type | res.send('Hello World', 'text/plain') |
res.set(headers) | Set multiple headers | res.set({ 'X-Custom': 'value' }) |
res.cookie(name, value, options) | Set cookie | res.cookie('token', 'abc123', { maxAge: 900000 }) |
res.clearCookie(name, options) | Clear cookie | res.clearCookie('token') |
res.sendFile(filePath, contentTypeOrRes, res) | Send file to client | app.sendFile('/path/to/file.html', 'text/html', res) |
Plugin System
| Method | Description | Example |
|---|---|---|
usePlugin(plugin, options) | Extend framework functionality with plugins | app.usePlugin(myPlugin, { config: true }) |
View Engine Methods
| Method | Description | Example |
|---|---|---|
setViewEngine(engine, options) | Configure template engine | app.setViewEngine('novax', { viewsPath: './views' }) |
render(file, data) | Render template with data | await app.render('home', { title: 'Home' }) |
addHelper(name, fn) | Add template helper function | app.addHelper('formatDate', (date) => {...}) |
addHelpers(helpers) | Add multiple template helpers | app.addHelpers({ helper1: fn1, helper2: fn2 }) |
Content Minification Methods
| Method | Description | Example |
|---|---|---|
minifyContent(content) | Minify HTML content | app.minifyContent(htmlString) |
minifyCSS(css) | Minify CSS content | app.minifyCSS(cssString) |
minifyJs(js) | Minify JavaScript content | app.minifyJs(jsString) |
New in v9.3.4
| Feature | Description | Example |
|---|---|---|
req.cookies | Automatic cookie parsing | const token = req.cookies.token; |
res.cookie() | Set cookies with options | res.cookie('user', 'john', { httpOnly: true }); |
res.clearCookie() | Clear cookies | res.clearCookie('session'); |
| Enhanced Templating | New @ syntax for templates | @if(user) Welcome @user.name! @end |
| Improved Error Handling | Better error messages and stack traces | app.on(500, (err) => `Error: ${err.message}`); |