-
-
Save nanha/1436065 to your computer and use it in GitHub Desktop.
Node.js performance tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use built in or binary modules | |
var crypto = require('crypto'); | |
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable socket pooling | |
var http = require('http'); | |
var options = {.....}; | |
options.agent = false; | |
var req = http.request(options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(express.session({ secret: "keyboard cat" })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name": "John"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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