5 ms·
> add fs.copyFile and fs.copyFileSync which allows for more efficient copying of files. FINALLY. I don;t know how long we could have come with this still being
by pitaj 9y ago
> add fs.copyFile and fs.copyFileSync which allows for more efficient copying of files.
FINALLY. I don;t know how long we could have come with this still being a thing you need a module for, or you have to code yourself.
Hopefully we get `fs.mkdirp` and `fs.remrf` somewhere down the line.
> Add support for ESM. This is currently behind the `--experimental-modules` flag and requires the `.mjs` extension.
I don't like the `.mjs` extension, but I understand the need for it, and I'm just glad that modules are finally here.
- sintaxi 9y agoI like .mjs because this is a good example of exactly what file extensions are meant for.
- blitmap 9y agoI probably don't understand what I'm looking at. I would like sendFile/sendFileSync - which would abstract over TransferFile on Windows.
- avaer 9y agoThe reason you're unlikely to see that in the node binary is presumably the same reason copyFile has taken so long: node aims to have a small core that enables a rich userspace. There's gotta be a very good reason to bog down the core with more stuff, since that equals less other stuff and more bugs. Some of the few valid reasons are ubiquity (which HTTP is, but Windows and sending files are not), or things that were impossible before (like no overhead file copy).
- coldtea 9y ago>node aims to have a small core that enables a rich userspace So, dogma? Because copying a file fits right in any kind of "small core" -- and helps create a more dependable and usable "rich userspace" which doesn't need to reinvent the wheel 200 times for basic stuff.
- spankalee 9y agoThe problem isn't the .mjs extension, but the unfortunate ability to import CommonJS modules, when that can already be done via require(). Dependency edges out of module land should be explicit, because those aren't going to work on the web, and the web matters more than node.
- styfle 9y agoI asked about the import syntax[0] and got an answer on GitHub. [0]: https://github.com/nodejs/node/pull/14369#issuecomment-329034997 https://github.com/nodejs/node/pull/14369#issuecomment-32903...
- likeclockwork 9y agoI think this decision is also short-sighted since ES Modules are now JS and CommonJS should be phased out over time, but now CommonJS is the default and holds the .js extension just complicating everything for short-term ease of use. They should have left requiring for CJS modules and let things be crappy for a while as requires and CJS are phased out. Eventually only ESM would remain except for in some abandoned packages, which could still be required. But now CJS is going to live forever because it's the default and ESM is opt in.
- Johnny_Brahms 9y agoWiuldnt implementing those be trivial? They are hardly going to be "too slow" like file copy might be, and with the JS love of small packages this should already be a solved problem.
- jaredklewis 9y agoThere most certainly are already packages that do this, as well as countless projects with a util.js file implementing a hodgepodge of such functions that are standards in many languages. But as a programmer I would say my biggest complaint against JS is the miserably small standard library. Thus every project has its own set of dependencies that have their own APIs. Two projects from different JS ecosystems are as different as projects in different languages altogether. There are trade offs to be sure, but I prefer the languages (and in this case platforms) that have batteries included.
- amelius 9y ago> Thus every project has its own set of dependencies that have their own APIs. Yes, this means that if your project depends on ten other projects, and all ten projects implement their own copy-file routine, your project will end up with ten copy-file routines.
- thom_nic 9y agoAs Larry Wall said, "Easy things should be easy." When working on a project and you need to copy something for the first time, you shouldn't have to do: * Ok I need to copy... What npm package does that again? * search NPM for copy * figure out which package is "best" * npm i some-copy-package * require("some-copy-packge") * do thing The first 4 steps should be unnecessary.
- coldtea 9y ago>I don't like the `.mjs` extension, but I understand the need for it, and I'm just glad that modules are finally here. I read that a lot. Why do people don't like the new extensions? Seems like the most elegant and programmatically more performant and less hassle free, solution to the issue. Everything else looks like a terrible kludge.
- _pmf_ 9y ago> I read that a lot. Why do people don't like the new extensions? Probably because you'll end up with .mts, .mjsx, .mts, .mtsx.
- coldtea 9y agoSo? If they are different types, it makes sense to have different extensions (e.g. if mts implies typescript module).
- josteink 9y ago> mts implies typescript module Or mpeg transport stream: https://en.m.wikipedia.org/wiki/MPEG_transport_stream https://en.m.wikipedia.org/wiki/MPEG_transport_stream
- kdkdkdk333ke 9y agoThey usually use .ts extension, or .tsv, .tsa according to the wiki article you just linked. .mts is unheard of.