Skip to content

v4.4.0

Choose a tag to compare

@LebCit LebCit released this 24 Mar 11:34
· 10 commits to main since this release

LiteNode 4.4.0 Release

I'm excited to announce the release of LiteNode 4.4.0, which introduces several powerful new features and enhancements to make your development experience even smoother.

New Features

🍪 Comprehensive Cookie Management

A complete cookie management system is now available:

  • setCookie(), getCookie(), and clearCookie() methods on the response object
  • New enableCookieParser() middleware to parse incoming cookies into req.cookies
  • Signed cookies for security with HMAC-SHA256 via createSignedCookies()
  • Full support for cookie options (httpOnly, secure, sameSite, etc.)
// Enable cookie parsing
app.enableCookieParser();

// Set a cookie
app.get('/login', (req, res) => {
  res.setCookie('session', 'abc123', { 
    maxAge: 3600,
    httpOnly: true,
    secure: true
  });
  res.redirect('/dashboard');
});

// Use signed cookies for added security
const signedCookies = app.createSignedCookies('strong-secret-key');

app.get('/secure', async (req, res) => {
  const userId = await signedCookies.getCookie(req, 'userId');
  if (!userId) return res.redirect('/login');
  res.json({ message: 'Secure content' });
});

🚀 Flexible Routing Enhancements

The router now supports:

  • Optional route parameters with /:param? syntax
  • Wildcard routes with /* (single segment) and /** (catch-all) patterns
  • New helper methods for common routing patterns:
    • app.any() - register a route for all HTTP methods
    • app.wildcard() - match a single path segment
    • app.catchAll() - match multiple path segments
// Optional parameters
app.get('/users/:id?', (req, res) => {
  // Matches both /users and /users/123
  const id = req.params.id || 'all';
  res.json({ id });
});

// Wildcard routes (matches a single path segment)
app.wildcard('/files', (req, res) => {
  const filename = req.params['*'];
  res.json({ file: filename });
});

// Catch-all routes (matches multiple path segments)
app.catchAll('/api', (req, res) => {
  const path = req.params['**'];
  res.json({ path });
});

// Handle any HTTP method
app.any('/health', (req, res) => {
  res.json({ status: 'ok', method: req.method });
});

🛠️ Enhanced HTTP Methods

Added body parsing to all HTTP methods that commonly use request bodies:

  • PUT, PATCH, and DELETE methods now automatically parse request bodies, just like POST
  • Access request data directly via req.body in all methods
  • Optional customMaxRequestSize parameter for all body-parsing methods
app.put('/users/:id', async (req, res) => {
  const userData = req.body;  // Body automatically parsed
  // Update user...
  res.json({ updated: true });
});

app.delete('/items', async (req, res) => {
  const itemIds = req.body.ids;  // Access parsed JSON data
  // Delete items...
  res.status(200).end();
}, 5); // 5MB max request size

📝 Template Engine Improvements

  • Support for backtick string literals (``) in templates, aligning with modern JavaScript
  • Enhanced dateFormat filter with improved robustness and formatting options
  • Better handling of template literals in HTML attributes with ternary operators
<!-- Now you can use backticks in templates -->
<option value="draft" {{ item.status="draft" ? `selected` : `` }}>Draft</option>

<!-- Enhanced date formatting -->
<span>{{ date | dateFormat('YYYY-MM-DD HH:mm') }}</span>

Installation & Upgrade

npm install litenode@latest

As always, this release maintains full backward compatibility, so upgrading should be seamless. Check out the documentation for detailed usage instructions.

I appreciate your feedback and contributions - enjoy the new features!