Post 3574194 by mdhughes@cybre.space
 (DIR) More posts by mdhughes@cybre.space
 (DIR) Post #3569712 by natecull@mastodon.social
       2019-01-31T01:41:05Z
       
       0 likes, 0 repeats
       
       Dumb Javascript/npm/git question time:Is there a handy guide anywhere to what 'good practice style' is for writing Node.js programs which might or might not be modules, but which contain multiple files using require() ).Eg:I have project foo.I want to track foo as a project in git, so I want it to be its own directory?But foo consists of a bunch of data and some .js files.I'd *like* to be able to just require('my-foo-subfile') but... I don't want them to all be npm projects.
       
 (DIR) Post #3569713 by tomasino@mastodon.sdf.org
       2019-01-31T01:48:57Z
       
       1 likes, 0 repeats
       
       @natecull you can require local stuff with ./ paths
       
 (DIR) Post #3570946 by sophieactual@occult.camp
       2019-01-31T02:05:24Z
       
       1 likes, 0 repeats
       
       @natecull Not the "right" answer but we'd maybe opt for therequire('.\my-foo-subfile') syntax, it just fits more cleanly if you're not going to go through the utterly terrifying, abstract everything into namespaces process.No toolchain we've ever met likes rigorous namespaces anyway.Very personal opinion, keystrokes as a development metric always fucks with the architecture.
       
 (DIR) Post #3574179 by mdhughes@cybre.space
       2019-01-31T05:23:38Z
       
       0 likes, 0 repeats
       
       @natecull In my Electron project, all source is in app/, so:% cd app% node -r ./Dice.js -i> Dice.d(1, 6)Thrown:ReferenceError: Dice is not defined> const { Dice } = require("./Dice");undefined> Dice.d(1, 6)1>
       
 (DIR) Post #3574194 by mdhughes@cybre.space
       2019-01-31T05:24:59Z
       
       0 likes, 0 repeats
       
       @natecull So I'm not sure what -r is supposed to do, but it didn't do require.
       
 (DIR) Post #3579336 by natecull@mastodon.social
       2019-01-31T10:11:14Z
       
       0 likes, 0 repeats
       
       @mdhughes The trick is you need the ./, but don't put the .js on the end.node -r ./Diceshould work!It is very frustratingly badly documented but it seems to get there in the end.
       
 (DIR) Post #3579811 by mdhughes@cybre.space
       2019-01-31T10:30:03Z
       
       0 likes, 0 repeats
       
       @natecull After a little investigation, seems the -r flag only does a preload so there's no startup cost, you still have to require in the REPL, or with -e commands.% node -e 'const {Dice}=require("./Dice");' -i> Dice.d(1, 6)5
       
 (DIR) Post #3580141 by clacke@libranet.de
       2019-01-31T10:46:31Z
       
       0 likes, 0 repeats
       
       What do the curlies around Dice do in that example?
       
 (DIR) Post #3580498 by mdhughes@cybre.space
       2019-01-31T11:04:11Z
       
       0 likes, 0 repeats
       
       @clacke Assigns from a multiple-return. Dice only has one,module.exports = {Dice};but many of my modules export a bunch of things, and then I have toconst {a,b,c}=require("module");
       
 (DIR) Post #3587491 by clacke@libranet.de
       2019-01-31T14:59:47Z
       
       0 likes, 0 repeats
       
       @mdhughes JS has tuples now? Cool.