Skip to content

Instantly share code, notes, and snippets.

@nanha
Forked from brikis98/BinaryModules.js
Created December 6, 2011 00:23
Show Gist options
  • Save nanha/1436065 to your computer and use it in GitHub Desktop.
Save nanha/1436065 to your computer and use it in GitHub Desktop.
Node.js performance tips
// Use built in or binary modules
var crypto = require('crypto');
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64");
// Disable socket pooling
var http = require('http');
var options = {.....};
options.agent = false;
var req = http.request(options)
app.use(express.session({ secret: "keyboard cat" }));
<!-- An example of a JavaScript template that can be rendered client side -->
<!DOCTYPE html>
<html>
<head>
<title>LinkedIn Mobile</title>
</head>
<body>
<div class="header">
<img src="http://mobile-cdn.linkedin.com/images/linkedin.png" alt="LinkedIn"/>
</div>
<div class="body">
Hello <%= name %>!
</div>
</body>
</html>
{"name": "John"}
<!-- An example of a simple webpage rendered entirely server side -->
<!DOCTYPE html>
<html>
<head>
<title>LinkedIn Mobile</title>
</head>
<body>
<div class="header">
<img src="http://mobile-cdn.linkedin.com/images/linkedin.png" alt="LinkedIn"/>
</div>
<div class="body">
Hello John!
</div>
</body>
</html>
// Good: write files asynchronously
fs.writeFile('message.txt', 'Hello Node', function (err) {
console.log("It's saved and the server remains responsive!");
});
// BAD: write files synchronously
fs.writeFileSync('message.txt', 'Hello Node');
console.log("It's saved, but you just blocked ALL requests!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment