1,463 reputation
58
bio website
location
age
visits member for 3 years, 9 months
seen May 23 at 8:42

May
23
answered In javascript, should object properties be declared on top of the function?
May
13
awarded  Critic
May
12
comment can i use json file as a module in node.js
@nikoss - .json files are automatically parsed as JSON by the node.js module loader. All described right here: nodejs.org/api/modules.html#modules_file_modules
May
12
comment can i use json file as a module in node.js
@nikoss - yes you call require("./jsonmodule.json"); in EVERY module in which you wish to use that shared data structure just like you have to do with the fs module and every time you call it, you get exactly the same cached object which you can modify from any place that has a reference to it.
May
12
comment can i use json file as a module in node.js
@nikoss - frustrating. No, we're talking about the result of var jsn = require("./jsonmodule.json");. That result (the contents of the jsn variable) is a Javascript object and is the exact same javascript object no matter how many times you call require("./jsonmodule.json"); in different places so you can use require("./jsonmodule.json");` in multiple places and they will all refer to the exact same Javascript object.
May
12
comment can i use json file as a module in node.js
@nikoss - see this nodejs.org/api/modules.html#modules_caching
May
12
comment can i use json file as a module in node.js
@nikoss - that result is still cached and there is still only one object no matter how many times you call require(). Did you actually try this and have a problem with it?
May
12
comment can i use json file as a module in node.js
@nikoss - either I'm not understanding your question or you're not understanding that once JSON is parsed, it is just a Javascript object that is shared by all who access it. Also node.js modules are cached. They are only ever loaded once and all subsequent require(modulename) return the exact same exports object and thus, in my example, the exact same Javascript object (thus it is shared by all).
May
12
comment can i use json file as a module in node.js
@nikoss - Not if you share a reference to the Javascript object you have with the other module. Then, both modules will be looking at exactly the same object. If one modifies it, the other will see that change. See what I added to my answer.
May
12
revised can i use json file as a module in node.js
added 90 characters in body
May
12
revised can i use json file as a module in node.js
added 90 characters in body
May
12
comment can i use json file as a module in node.js
@nikoss - what do you mean globally change the file? Any reference you have to the data is a reference to the one and only one copy so any changes you make will be seen by all. If you want to persistently change the file so it will load up with different data the next time your server starts, then you need to store the changes persistently (in a database, in a JSON file, etc...) and have your module explicitly load the data from wherever you saved it to.
May
12
answered can i use json file as a module in node.js
Apr
27
comment Why is it common to put an underscore before a method in JavaScript?
Often, an underscore prefix means this method is not meant for public consumption. I don't know about jQuery UI specifically.
Apr
22
answered How do I make a JavaScript promise return something other than a promise?
Mar
23
comment Are web sockets a browser feature or supplied by a specific OS version?
@AlexLL - All versions of OSes have TCP/IP which is the only thing webSockets need from the OS. So, yes you can run the latest Firefox on XP (if Firefox chooses to support XP) and webSockets will work there.
Mar
23
answered Are web sockets a browser feature or supplied by a specific OS version?
Mar
4
comment Executing scripts in parallel based on dependency tree
You get parallelism from the OS by spawning separate processes for each task you want to run in parallel. You get serial execution by running one task and then monitoring its completion before you start the next task. The specifics of how to do this depend entirely upon which development environment you choose to write the controlling program in.
Feb
26
comment Declaring JS Functions in Two Ways : What's the Benefit?
@asprin - I added some code examples.
Feb
26
revised Declaring JS Functions in Two Ways : What's the Benefit?
added 759 characters in body