-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Node.js static server example #13113
Conversation
Preview URLs External URLs (1)URL:
(this comment was updated 2022-09-28 00:13:22.686039) |
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
files/en-us/learn/server-side/node_server_without_framework/index.md
Outdated
Show resolved
Hide resolved
@tshemsedinov This is excellent thanks. @teoli2003 I've just done a basic subedit, not a technical review - left that for you. |
@hamishwillee thanks, I'll fix that in a few days, and can provide more simple examples of modern pure node.js and framework-agnostic approach. Refs: https://github.com/mdn/content/discussions/13124 |
Co-authored-by: Hamish Willee <[email protected]>
+1. Great idea! |
Apologies @tshemsedinov - I did a subedit back in February but then thought I'd handed over to @teoli2003 for technical review. Obviously I did not do so properly @teoli2003 Can you review and tell me if you are happy with this as a technical update? My take on it is that it is a little "succint" for a learn article - but then so was the original. It lost some of the possible errors from the file read too. What I don't know is if this is a pattern that we would be OK for people to copy. Also whether the introductory statement is true - i.e. is this everything needed for a basic static file server. |
I'm more familiar with Node than web (though I'm not a back end so I'm not that familiar with HTTP servers). The code here looks good enough to be copied—although it's definitely quite simple! |
|
||
```js | ||
const http = require('http'); | ||
const fs = require('fs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: as a mid-term goal I'd like MDN Node tutorials to embrace Node ESM. More and more dependencies are migrating to ESM and you can't require
ESM, which means for forward compatibility all user projects should start as ESM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Josh-Cena: I think this is a great point. To give it more visibility, can you start a discussion about it (I believe the consensus will be easy to reach) at mdn/mdn-community ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I should—just haven't got to it yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hamishwillee new example don't need to check
Listed will take about +10 lines each ☺ |
<details> | ||
<summary>CJS implementation</summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we reached resolution with mdn/mdn-community#191, could you keep this CJS-only? This is simply confusing without another explanatory document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Josh-Cena done
Thanks @tshemsedinov . @Josh-Cena @teoli2003 I think we should get this in when you are happy. However it might be good to extend this in some or all of the ways outlined in #13113 (comment) as a post process - in particular if that can be done in separate sections such that a user can learn how each part is put together. Do you have options about what you think such an example should do in the ideal case? |
merging. If there are still issues, we can edit again. |
Providing an ESM version 👍 Assuming that from now on all codebases across the globe have migrated to ESM and not providing a CJS version equals to giving those who maintain legacy no other choice than to look elsewhere for a simple node http server. PS, who performed a code review on this? |
@charlesvg Passive-aggressive comments have no place on MDN and is borderline CoC violation. The argument that there are people "maintaining legacy CJS applications" while needing to read learning materials to know how to write a simple HTTP server seems unlikely. We always assume people start from scratch and have no tech debt; otherwise it's hard for us to set any common ground. The argument is also non-unique to ESM. You could ask: why does MDN use If you find |
Summary
Motivation
Improve and renew legacy codebase.
Metadata