@trivajs/shortcuts
v1.0.0
Published
IDE snippets/shortcuts for Triva framework - auto-installs to VS Code, VS Code Insiders, and Atom
Maintainers
Readme
@trivajs/shortcuts
IDE snippets and shortcuts for Triva framework. Automatically installs code snippets to VS Code, VS Code Insiders, and Atom.
Installation
npm install triva
npm install @trivajs/shortcutsThe snippets will automatically install to your IDE(s) on npm install and automatically uninstall on npm uninstall.
Supported IDEs
✅ VS Code - Detects and installs to User/snippets/
✅ VS Code Insiders - Detects and installs separately
✅ Atom - Installs to ~/.atom/snippets.cson
Available Snippets
Server Setup
| Prefix | Description |
|--------|-------------|
| triva-build | Build and configure Triva server |
| triva-server | Create basic Triva server |
| triva-config | Full Triva configuration |
Routes
| 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 |
Middleware
| Prefix | Description |
|--------|-------------|
| triva-middleware | Create middleware function |
| triva-cors | Add CORS middleware |
| triva-cookies | Cookie parser middleware |
Cache
| 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 |
Database Adapters
| Prefix | Description |
|--------|-------------|
| triva-mongodb | Configure MongoDB cache |
| triva-redis | Configure Redis cache |
| triva-postgres | Configure PostgreSQL cache |
Features
| Prefix | Description |
|--------|-------------|
| triva-errors | Configure error tracking |
| triva-logging | Configure request logging |
| triva-throttle | Configure rate limiting |
| triva-throttle-policy | Rate limiting with policies |
Usage
In VS Code or Atom, simply type the prefix and press Tab to expand the snippet.
Example: Create Basic Server
- 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);Example: Add CORS
- 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']
}));Example: Cache Pattern
- 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 });How It Works
Automatic Detection
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
Installation Paths
VS Code (Windows):
%APPDATA%\Code\User\snippets\javascript.json
%APPDATA%\Code\User\snippets\typescript.jsonVS Code (macOS):
~/Library/Application Support/Code/User/snippets/javascript.json
~/Library/Application Support/Code/User/snippets/typescript.jsonVS Code (Linux):
~/.config/Code/User/snippets/javascript.json
~/.config/Code/User/snippets/typescript.jsonAtom (All platforms):
~/.atom/snippets.csonUpdate Behavior
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
Uninstallation
npm uninstall @trivajs/shortcutsAutomatically removes all Triva snippets from your IDE(s) on uninstall.
Manual Installation
If automatic installation doesn't work, you can manually add snippets:
VS Code
- 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
Atom
- Open
~/.atom/snippets.cson - Add Triva snippets under
.source.js:or.source.ts: - Save and reload Atom
Snippet Format
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
Troubleshooting
Snippets Not Appearing
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
Permission Errors
Run npm with appropriate permissions:
# Linux/macOS
sudo npm install @trivajs/shortcuts
# Windows (as Administrator)
npm install @trivajs/shortcutsMultiple IDEs
If you have multiple IDEs, snippets install to all detected IDEs. This is intentional to ensure availability.
Development
Add New Snippets
Edit triva/snippets/triva.json:
{
"Snippet Name": {
"prefix": "trigger-text",
"body": [
"line 1",
"line 2 with ${1:placeholder}",
"$0"
],
"description": "What this snippet does"
}
}Test Locally
cd extensions/shortcuts
npm install
# Snippets auto-install to your IDEContributing
To add snippets:
- Edit
snippets/triva.json(in main Triva repo) - Follow VS Code snippet format
- Test installation
- Submit PR
Related
Contributing
Issues and PRs welcome! See main Triva repository for contribution guidelines.
Triva Framework - Main framework
License
MIT License - see LICENSE file
