IDE snippets and shortcuts for Triva framework. Automatically installs code snippets to VS Code, VS Code Insiders, and Atom.
npm install @trivajs/shortcutsThe snippets will automatically install to your IDE(s) on npm install and automatically uninstall on npm uninstall.
✅ VS Code - Detects and installs to User/snippets/
✅ VS Code Insiders - Detects and installs separately
✅ Atom - Installs to ~/.atom/snippets.cson
| Prefix | Description |
|---|---|
triva-build |
Build and configure Triva server |
triva-server |
Create basic Triva server |
triva-config |
Full Triva configuration |
| Prefix | Description |
|---|---|
triva-get |
Create GET route |
triva-post |
Create POST route with body parsing |
triva-put |
Create PUT route with params |
triva-del |
Create DELETE route |
triva-auth |
Protected route with authentication |
| Prefix | Description |
|---|---|
triva-middleware |
Create middleware function |
triva-cors |
Add CORS middleware |
triva-cookies |
Cookie parser middleware |
| Prefix | Description |
|---|---|
triva-cache-get |
Get value from cache |
triva-cache-set |
Set value in cache with TTL |
triva-cache-pattern |
Cache pattern with get/set |
| Prefix | Description |
|---|---|
triva-mongodb |
Configure MongoDB cache |
triva-redis |
Configure Redis cache |
triva-postgres |
Configure PostgreSQL cache |
| Prefix | Description |
|---|---|
triva-errors |
Configure error tracking |
triva-logging |
Configure request logging |
triva-throttle |
Configure rate limiting |
triva-throttle-policy |
Rate limiting with policies |
In VS Code or Atom, simply type the prefix and press Tab to expand the snippet.
- Type
triva-serverand pressTab - Fill in the placeholders (route, response, port)
- Press
Tabto move between placeholders
import { build, get, post, listen } from 'triva';
await build({
cache: { type: 'memory' }
});
get('/api', (req, res) => {
res.json({ message: 'Hello' });
});
listen(3000);- Type
triva-corsand pressTab - Configure origin, credentials, methods
import { cors } from '@trivajs/cors';
use(cors({
origin: 'https://example.com',
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization']
}));- Type
triva-cache-patternand pressTab - Configure cache key, data source, TTL
const cacheKey = 'users:123';
const cached = await cache.get(cacheKey);
if (cached) {
return res.json({ source: 'cache', data: cached });
}
const data = await db.getUser(123);
await cache.set(cacheKey, data, 3600000);
res.json({ source: 'database', data });The package automatically detects your IDE(s) by:
-
Environment variables (high confidence)
VSCODE_CWD,TERM_PROGRAM,ATOM_HOME
-
Filesystem checks (lower confidence)
- VS Code config directories
- Atom config directories
-
Fallback behavior
- If no IDE detected → installs to ALL supported IDEs
- Ensures snippets are available even if detection fails
VS Code (Windows):
%APPDATA%\Code\User\snippets\javascript.json
%APPDATA%\Code\User\snippets\typescript.json
VS Code (macOS):
~/Library/Application Support/Code/User/snippets/javascript.json
~/Library/Application Support/Code/User/snippets/typescript.json
VS Code (Linux):
~/.config/Code/User/snippets/javascript.json
~/.config/Code/User/snippets/typescript.json
Atom (All platforms):
~/.atom/snippets.cson
When you update @trivajs/shortcuts:
- New snippets are added
- Changed snippets are updated
- Existing snippets are preserved (no duplicates)
- Removed snippets stay until package is uninstalled
npm uninstall @trivajs/shortcutsAutomatically removes all Triva snippets from your IDE(s) on uninstall.
If automatic installation doesn't work, you can manually add snippets:
- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) - Select "Preferences: Configure User Snippets"
- Choose "javascript.json" or "typescript.json"
- Copy snippets from
triva/snippets/triva.json
- Open
~/.atom/snippets.cson - Add Triva snippets under
.source.js:or.source.ts: - Save and reload Atom
Snippets use standard VS Code format with:
- Placeholders -
${1:default}- Tab to navigate - Choices -
${1|option1,option2|}- Select from list - Variables -
$0- Final cursor position
VS Code:
- Restart VS Code
- Check:
File > Preferences > User Snippets - Verify snippets in
javascript.jsonortypescript.json
Atom:
- Reload Atom (
Ctrl+Shift+F5/Cmd+Shift+F5) - Check
~/.atom/snippets.cson - Verify correct CSON syntax
Run npm with appropriate permissions:
# Linux/macOS
sudo npm install @trivajs/shortcuts
# Windows (as Administrator)
npm install @trivajs/shortcutsIf you have multiple IDEs, snippets install to all detected IDEs. This is intentional to ensure availability.
Edit triva/snippets/triva.json:
{
"Snippet Name": {
"prefix": "trigger-text",
"body": [
"line 1",
"line 2 with ${1:placeholder}",
"$0"
],
"description": "What this snippet does"
}
}cd extensions/shortcuts
npm install
# Snippets auto-install to your IDETo add snippets:
- Edit
snippets/triva.json(in main Triva repo) - Follow VS Code snippet format
- Test installation
- Submit PR
- Triva Framework - Main framework
- @trivajs/cors - CORS middleware
- @trivajs/cli - CLI tools
MIT License - see LICENSE file