{"id":41328,"library":"jsend","title":"jsend","description":"Utilities and middleware for creating, validating, and handling jsend JSON response objects in Node.js applications. Version 1.1.0 is the latest stable release. Provides functions to construct success/fail/error responses, validate them (including strict mode), convert from Node-style callbacks, and Express middleware to attach res.jsend helpers. Key differentiator: fully implements the jsend spec with built-in validation and middleware, unlike ad-hoc implementations.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/Prestaul/jsend","tags":["javascript","jsend","middleware","json","status"],"install":[{"cmd":"npm install jsend","lang":"bash","label":"npm"},{"cmd":"yarn add jsend","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsend","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single function (the jsend object) as default. Named import will not work.","wrong":"import { jsend } from 'jsend'","symbol":"default import","correct":"import jsend from 'jsend'"},{"note":"CommonJS require works fine. The returned value is the jsend object.","wrong":null,"symbol":"require","correct":"const jsend = require('jsend')"},{"note":"Strict mode is configured by calling the default export as a function with an options object. It returns a new jsend instance.","wrong":"import jsend from 'jsend';\njsend.strict = true","symbol":"strict mode","correct":"import jsend from 'jsend';\nconst strictJsend = jsend({ strict: true })"}],"quickstart":{"code":"import jsend from 'jsend';\n\n// Create a success response\nconst successRes = jsend.success({ foo: 'bar' });\nconsole.log(successRes);\n// { status: 'success', data: { foo: 'bar' } }\n\n// Create a fail response\nconst failRes = jsend.fail({ validation: 'missing field' });\nconsole.log(failRes);\n// { status: 'fail', data: { validation: 'missing field' } }\n\n// Create an error response\nconst errorRes = jsend.error('Something went wrong');\nconsole.log(errorRes);\n// { status: 'error', message: 'Something went wrong' }\n\n// Validate a response\nconsole.log(jsend.isValid(successRes)); // true\n\n// Express middleware example\nimport express from 'express';\nconst app = express();\napp.use(jsend.middleware);\napp.get('/data', (req, res) => {\n  res.jsend.success({ id: 1 });\n});\napp.listen(3000);","lang":"javascript","description":"Demonstrates basic usage: creating success/fail/error responses, validating, and using the Express middleware."},"warnings":[{"fix":"Use the same instance consistently or re-create strict version.","message":"When using strict validation via jsend({ strict: true }), the returned object is a new instance with its own methods. Mixing strict and non-strict instances will not work as expected.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually check error and call res.jsend.error() instead.","message":"The middleware attaches res.jsend which can be used as a callback (res.jsend(err, data)). However, if err is truthy, it will call res.jsend.fail(data) but the spec expects res.jsend.error(message) for errors. This may cause confusion.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use jsend.fromArguments or manually parse the response.","message":"jsend.forward does not handle errors correctly for 'fail' status; it treats 'fail' as an error (setting the callback's first argument) which may not be expected.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"None needed.","message":"No breaking changes known; version 1.1.0 is stable and backward-compatible with 1.x.","severity":"breaking","affected_versions":">=1.0.0 <=1.1.0"}],"env_vars":null,"search_vec":"'1.1.0':18 'ad':64 'ad-hoc':63 'applic':16 'attach':45 'built':57 'built-in':56 'callback':40 'construct':27 'convert':35 'creat':6 'differenti':49 'express':42 'fulli':50 'function':25 'handl':9 'helper':47 'hoc':65 'implement':51,66 'includ':32 'javascript':67 'jsend':1,10,53,68 'json':11,70 'key':48 'latest':21 'middlewar':4,43,61,69 'mode':34 'node':38 'node-styl':37 'node.js':15 'object':13 'provid':24 'releas':23 'res.jsend':46 'respons':12,29 'spec':54 'stabl':22 'status':71 'strict':33 'style':39 'success/fail/error':28 'unlik':62 'util':2 'valid':7,30,59 'version':17","created_at":"2026-06-04T18:51:52.918626+00:00","updated_at":"2026-06-04T18:51:52.918626+00:00","problems":[{"fix":"Use 'import jsend from \"jsend\"' or 'const jsend = require(\"jsend\")'","cause":"Using named import instead of default import.","error":"TypeError: jsend.isValid is not a function"},{"fix":"Ensure app.use(jsend.middleware) is called before defining routes.","cause":"Middleware not applied to the Express app before route definition.","error":"res.jsend is not a function"},{"fix":"Disable strict mode or remove extra properties from the response.","cause":"Strict mode is enabled and the response contains extra properties.","error":"ValidationError: Unexpected property 'junk'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Prestaul/jsend#readme","github":"ssh://git@github.com/Prestaul/jsend","docs":null,"changelog":null,"pypi":null,"npm":"jsend","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}