Posts

Showing posts with the label express

How to write TypeScript definition for a middleware that adds property to the response?

I'd like to use express-boom for express with TypeScript. It lacks of typings so I'd like to write my own. Just make it compile is trivial. This middleware decorates the res object with a property boom (derived from the boom module): But with typescript I need to cast it because neither http.ServerResponse and Express.Response have the boom property, of course: Which is the cleanest way to do it? Which are other typed middleware that are doing a similar thing? There's quite a few other Express middlewares you can use as examples, e.g. Method-Override, and its type definitions. As a more concrete example, if you want to add this .boom property to the response object, you should just need to create a type definition (express-boom.d.ts) containing: Create a type definition file express-boom.d.ts containing: This declares that the interface Express.Response has an additional property named boom . The declared type of the property is the same as that of the namespace Boom ...

how to solve webpack and bcrypt incompatibility issue

I found bcrypt is not compatible with webpack . Quote from issue bcrypt is not designed to be run there. bcrypt is a native (C++) module and only runs on node environments. You can use bcrypt.js as a (mostly) drop-in replacement. However bcrpt.js is 30% slower than bcrypt . And since I'm really using node environment, I still want to use bcrypt rather than bcrypt.js . What should I do? Should I bundle my JS code without dependency in node_module , and during deployment npm install ? For those who downvoted this question: This shouldn't go to webpack or bcrypt github issues which are not support forum. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.