
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
express-as-promised
Advanced tools
This is simply the Express we all know and love with a few enhancements to support returning various values including promises.
So instead of:
app.get('/', function(request, response) {
return quote.fetch().then(function(quote) {
response.send(quote);
});
});
We can simply just return the promise:
app.get('/', function() {
return quote.fetch();
});
Both will result in something like:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 87
Date: Sat, 12 Jul 2014 14:40:14 GMT
Connection: keep-alive
{quote: "The true measure of a man is how he treats somebody that can do him no good."}
You can return strings and objects or their promised equivalent.
app.get('/', function() {
var promise = bluebird.resolve('Hello world');
return promise;
});
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 11
Date: Sat, 12 Jul 2014 14:40:14 GMT
Connection: keep-alive
Hello world
app.get('/', function( {
return 'Hello world';
})
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 11
Date: Sat, 12 Jul 2014 14:40:14 GMT
Connection: keep-alive
Hello world
If your callback throws or returns an error a stack trace will be sent, for example:
app.get('/', function() {
throw new Error('Something went wrong.');
});
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 1059
Date: Sat, 12 Jul 2014 14:41:56 GMT
Connection: keep-alive
Error: Something went wrong
at /Users/michael/Projects/express-as-promised/tests.js:5:9
at /Users/michael/Projects/express-as-promised/main.js:13:19
at Object._callback [as handle] (/Users/michael/Projects/express-as-promised/main.js:29:9)
at next_layer (/Users/michael/Projects/express-as-promised/node_modules/express/lib/router/route.js:113:13)
at Route.dispatch (/Users/michael/Projects/express-as-promised/node_modules/express/lib/router/route.js:117:5)
at /Users/michael/Projects/express-as-promised/node_modules/express/lib/router/index.js:222:24
at Function.proto.process_params (/Users/michael/Projects/express-as-promised/node_modules/express/lib/router/index.js:288:12)
at next (/Users/michael/Projects/express-as-promised/node_modules/express/lib/router/index.js:216:19)
at Layer.expressInit [as handle] (/Users/michael/Projects/express-as-promised/node_modules/express/lib/middleware/init.js:23:5)
at trim_prefix (/Users/michael/Projects/express-as-promised/node_modules/express/lib/router/index.js:263:17)
Unless NODE_ENV
is set to production, then you'll just get:
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 20
Date: Sat, 12 Jul 2014 14:45:51 GMT
Connection: keep-alive
Interal Server Error
You can still use a custom status code when required:
app.get('/', function(req, res) {
res.status(403);
return 'Not allowed';
});
HTTP/1.1 403 Forbidden
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 11
Date: Sun, 13 Jul 2014 05:17:03 GMT
Connection: keep-alive
Not allowed
And everything you're doing right now with Express, should just work.
app.get('/', function(req, res, next) {
res.status(403);
next();
}, function(req, res) {
res.send('Hello world');
});
or even:
app.get('/', function(req, res, next) {
res.status(403);
next();
}, function(req, res) {
return 'Hello world';
});
Just simply run npm test
FAQs
This is simply the Express we all know and love promisified.
The npm package express-as-promised receives a total of 0 weekly downloads. As such, express-as-promised popularity was classified as not popular.
We found that express-as-promised 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.