1,463 reputation
58
bio website
location
age
visits member for 3 years, 8 months
seen yesterday

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
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.
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.
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
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
24
comment Is there any reason to use the “var” keyword in ES6?
I haven't tried this yet (since I'm not yet writing ES6 code), but it seems that using var as a conscious indicator that this variable is intended to be scoped to the entire function might be a useful "self-documenting" convention.
Feb
8
comment Should I prefer classes or singletons in JavaScript/Node?
I wouldn't design yourself into a singleton design unless the type of object could NEVER have more than one. If you might ever want more than one, then you may as well design an object that you can instantiate more than one of.
Jan
30
comment Why is the Document Object Model the view?
The DOM is the visual representation or visual presentation. Most people would call that the view (what you see and what a user interacts with). It's the Document Object Model to the browser which just means it's the structure that the browser uses to display things, but it's not the data model or object model of your app. Yes, the terminology is a bit unfortunate, but it's not your app's model - that would be something completely different.
Jan
8
comment JavaScript program design: to what degree should I separate logic and display?
My preferred answer here is that you should assess your immediate goal and any likely future goals you might have with this code and find a design that is clear, concise, extensible in likely directions, yet efficient in implementation. This means you don't go way out of your way to decouple things that are unlikely to need to be decoupled, but at the same time, you pick an intelligent architecture that is easy to understand, implement, debug and produce solid maintainable code with while meeting the needs of your immediate project and any likely follow-on projects.
Jan
8
comment JavaScript program design: to what degree should I separate logic and display?
Javascript, by its nature is NO more coupled to the HTML and CSS than you write it to be. Your Javascript code has no generic coupling to your HTML or CSS unless you make it be coupled. So, I think your supposition here is entirely flawed that by its nature things are coupled - they aren't.
Dec
24
comment JavaScript strict mode compatibility
@Izkata - In strict mode, this === undefined in a regular function call. That is different than this === window in a regular function call in non-strict mode. I'm just pointing outa difference between strict mode and non-strict mode. Perhaps you didn't know that Javascript changes the value of this when you make a regular function call.
Dec
3
comment What exactly is the meaning of “node” in Document Object Model (DOM)?
See here: stackoverflow.com/questions/9979172/…
Nov
19
comment how can I minimize my ajax calls to the server while creating a dashboard
Yeah, if you have buggy code, you app won't work - all you have to do is write code that works. There's no inherent reliability issue with distributing data to different parts of your app without making separate Ajax calls. If you are implementing it like a cache, then you may need to implement cache expiration so you get fresh results when you want fresh results.