![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Express-like framework for CLI apps.
$ npm install sushi --save
myapp.js:
const sushi = require('sushi');
const app = sushi();
app.command('start', function () {
console.log('start command');
});
app.command('stop', function () {
console.log('stop command');
});
app.command('index', function () {
console.log('index command');
});
app.run();
Output:
$ node myapp.js start
start command
$ node myapp.js stop
stop command
$ node myapp.js
index command
Program arguments are parsed using minimist.
Command can access arguments via req.args
:
app.command('start', function (req) {
var name = req.args._[0];
var delay = req.args.delay;
console.log('start', name, 'with', delay, 'delay');
});
$ node myapp.js start my-process --delay 500ms
start my-process with 500ms delay
You can also customize the way minimist
parses arguments by passing args
options (see minimist):
const app = sushi({
args: {
boolean: ['verbose']
}
});
Index command is executed when other commands don't match the arguments:
app.command('index', function () {
console.log('index command');
});
$ node myapp.js
index command
$ node myapp.js hello
Middleware is a function, that modifies the context or arguments before target command is executed.
app.use(function (req, next) {
req.context.ok = true;
// call `next()` when done
next();
});
app.command('start', function (req) {
req.context.ok === true; // true
console.log('start command');
});
Middleware can also abort execution:
app.use(function (req, next) {
var err = new Error('Fatal error');
next(err);
});
app.command('start', function (req) {
// won't be executed
});
app.on('error', function (err) {
// err is the Error instance from middleware
err.message === 'Fatal error'; // true
});
When one of the middleware or command itself throws an error,
error
event is emitted:
app.on('error', function (err) {
// err is the Error instance
});
You can use it to display a friendly error message, report it, etc.
Here's the list of middleware you can use with Sushi:
$ npm test
MIT © Vadym Demedes
FAQs
Sushi
The npm package sushi receives a total of 2,055 weekly downloads. As such, sushi popularity was classified as popular.
We found that sushi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.