nodejs / examples

A repository of runnable Node.js examples that go beyond "hello, world!"
MIT License
649 stars 343 forks source link

Feature/fastify examples session #26

Open ghinks opened 4 years ago

ghinks commented 4 years ago

A slightly more advanced example starting with

ghinks commented 4 years ago

@mcollina ok, so there may be a misunderstanding by myself on this subject. Should all route handlers be async even if they are synchronous themselves. Is this a general practice? Or am I doing this correctly but you would rather see examples of asynchronous behavior with these session examples too? ( PS sincere thanks for reviewing )

mcollina commented 4 years ago

Should all route handlers be async even if they are synchronous themselves. Is this a general practice?

I recommend this for examples because adding an asynchronous behavior is the normal case. There are significant differences between returning a value (or throwing) in an async function vs a normal one as everything is wrapped in a promise, it resolves in the next tick etc.

Starting from v3 this pattern is supported so everything works fine here, but it looks good only in non-production cases.

ghinks commented 4 years ago

ok, understood. I thought that was what you would say. Will make appropriate changes.

ghinks commented 4 years ago

Then I shall try that. Live and Learn :)

bnb commented 3 years ago

cc @mhdawson is including an SSL cert here okay given the cryptography exports thing?

bnb commented 3 years ago

oops didn't mean to close

ghinks commented 3 years ago

many thanks for the comments. I shall update the readme to follow the style suggested. The certificates are local host and are self signed. There are no cryptographic secrets within them they just allow for session to be tested on localhost using the secure setting. Otherwise the example is not representative.

ghinks commented 3 years ago

I have had a look at the example readme files you gave. Apart from the IBM example they are all installable modules and only the IBM readme is an example, so they don't really pertain to this type of examples repo. The IBM readme does in fact start off with in this tutorial. I am not really sure what is being asked for.

bnb commented 3 years ago

Here's an example of a server from @Thiruppathi that aligns more with what's being asked for :)

https://github.com/nodejs/examples/commit/6f689d52269b4c0d818f0835d313f99137311904