r/node • u/LeCoupa • Feb 03 '18
Node.js Cheatsheet - Everything you should know in one single file
https://github.com/LeCoupa/awesome-cheatsheets/blob/master/backend/node.js27
u/Bibliophile777 Feb 03 '18
Thanks for this amazing contribution, I'm just starting to learn Node.JS
11
47
Feb 03 '18 edited Feb 03 '18
exports.area = function (r) {
return 3.14 * r * r;
};Should be:
exports.area = function (r) {
return Math.PI * r * r;
};23
35
8
u/anonym1970 Feb 03 '18
Well, “wrong” and “less precise” are different things.
3
2
u/Nimelrian Feb 04 '18
If you're using node > 8 you can also use
exports.area = function (r) { return Math.PI * r ** 2; };Not saying that you should (for square the simple multiplication is more easier to grasp on first read), but for higher exponents it's worth to throw that way in :)
1
u/DuBistKomisch Feb 04 '18
exports.area = function (r) { return require('const-pi') * r * r; };for the true node experience
2
u/mjgood91 Feb 04 '18
You shouldn't be using requires in the middle of a code block like that. Put the require at the top in
const pi = require('const-pi');
Then change the function to return pi * r * r;
2
u/DuBistKomisch Feb 05 '18
The code is intentionally bad, you shouldn't be requiring something that basic in the first place.
1
12
u/deadcoder0904 Feb 03 '18
Thanks for it. Why don't you contribute to https://devhints.io !
I think it has better UI but you have better CheatSheet.
7
3
u/1-800-BICYCLE Feb 03 '18
I've been using Node.js for years and didn't know about ref and unref. Thanks!
1
3
4
1
u/clockdivide55 Feb 04 '18
I'm starting a new job tomorrow where I'll be doing Node development. This will be very useful, thanks.
1
2
2
2
u/supamerz Feb 04 '18
This is great, good work. Very nice and readable. Its like a beautiful walkthrough to Node
2
u/JonnyBoy89 Feb 06 '18
Thank you for sharing this awesome sheet! Just learning Node and this is a huge help
1
u/DrRandomMortis Feb 03 '18
Sweet! I am just about to start working on project in NodeJS. Thanks a lot!
1
1
1
1
1
0
Feb 04 '18
[deleted]
4
u/LeCoupa Feb 04 '18 edited Feb 04 '18
I always do a cheatsheet when I want to improve my skills on a programming language. I started doing these kind of things a long time ago on Gist (https://gist.github.com/LeCoupa) and I decided a few months ago to create a repo instead (better as I can keep track of the history by committing changes). It is also a way to save time when I am coding as everything is organized in a single file. :-)
Most of the content is coming from official documentations or some books I have read.
0
0
35
u/MinicD Feb 03 '18
Creating new Buffer with this syntax is deprecated. Now it should be like: