![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Emergency Exits for Diet.js
If you're trying to use Promises in Diet you may have noticed that you can't just throw an error to trigger a 500 Sever Error, since it ends up swallowed by the Promise chain. As far as I can tell, there's no way to directly call the error route in Diet.js.
This module provides middleware to add a method to the signal object ($) to throw an error out of a Promise chain.
npm install --save diet-500
Note that in modern versions of NPM (>= 5) you don't actually need the --save
flag.
const server = require('diet')
const serverError = require('diet-500')
app = server()
app.listen('http://localhost:8888')
app.header(serverError)
app.get('/', function ($) {
return Promise.resolve().then(() => {
throw new Error('Time to die!')
}).catch(err => {
$.err(err)
})
})
By default, the method attached to the signal is err
. You can specify a different method name
if you like.
const server = require('diet')
const serverError = require('diet-500').methodName('error500')
app = server()
app.listen('http://localhost:9999')
app.header(serverError)
app.get('/', function ($) {
return Promise.reject(new Error('GOING DOWN'))
.catch(err => {
$.error500(err)
})
})
FAQs
Manually send 500 server errors in Diet.js
The npm package diet-500 receives a total of 1 weekly downloads. As such, diet-500 popularity was classified as not popular.
We found that diet-500 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.