r/node • • Feb 03 '18

Node.js Cheatsheet - Everything you should know in one single file

https://github.com/LeCoupa/awesome-cheatsheets/blob/master/backend/node.js
459 Upvotes

40 comments sorted by

35

u/MinicD Feb 03 '18
new Buffer(array)

Creating new Buffer with this syntax is deprecated. Now it should be like:

Buffer.from(array)

16

u/LeCoupa Feb 03 '18

You're right, I have just updated the cheatsheet. Thanks :-)

27

u/Bibliophile777 Feb 03 '18

Thanks for this amazing contribution, I'm just starting to learn Node.JS

11

u/LeCoupa Feb 03 '18

You're welcome :-) Good luck!

47

u/[deleted] 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

u/LeCoupa Feb 03 '18

You're right. Better be precise. I have updated the cheatsheet. Thanks :-)

35

u/[deleted] Feb 03 '18

Pull request > reddit comment

26

u/Untgradd Feb 04 '18

something > nothing

5

u/OzziePeck Feb 04 '18

unicorn === horse in disguise.

8

u/anonym1970 Feb 03 '18

Well, “wrong” and “less precise” are different things.

3

u/[deleted] Feb 04 '18

I don't think he said it's wrong.

4

u/anonym1970 Feb 04 '18

He edited the post.

3

u/[deleted] Feb 04 '18

I see. I apologize

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

u/siamthailand Feb 04 '18

Looks like it triggered a few!

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

u/LeCoupa Feb 03 '18

Thanks :-) I didn't know this website. The UI is great!

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

u/LeCoupa Feb 03 '18

You're welcome :-)

3

u/NoInkling Feb 04 '18

Should probably add util.promisify() in there.

1

u/LeCoupa Feb 04 '18

Thanks, did not know this function :-)

4

u/HeyGuysImMichael Feb 03 '18

Good goosh this is nice

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

u/LeCoupa Feb 04 '18

Good luck! :)

2

u/TrainedWrongAsAJoke Feb 03 '18

Thank you very much!

2

u/DeleteMyOldAccount Feb 03 '18

Huh anyone know why this page is super laggy on mobile?

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

u/scriptfailmatrix Feb 03 '18

Sweeeeeetnesszz

1

u/Tillhony Feb 03 '18

Learning a lot going through this

1

u/epic_within Feb 04 '18

Great stuff!

I suggest you post it in r/learnprogramming, too.

1

u/[deleted] Feb 04 '18

It's really helpful. Thank you

1

u/texasbruce Feb 04 '18

Thanks. Forked.

0

u/[deleted] 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

u/[deleted] Feb 04 '18

[deleted]

1

u/LeCoupa Feb 04 '18

This would be great! Thanks :)

0

u/[deleted] Feb 04 '18

[deleted]

1

u/LeCoupa Feb 04 '18

You're welcome, feel free to contribute if you want to help me on this. :-)