How to detect oncomplete function when using readline module in node.js? - node.js

I am trying to read files 1 line at a time using this doc
https://nodejs.org/api/readline.html
from the answer here
Read a file one line at a time in node.js?
proposed by Dan.
The problem is, it doesn't specify how to call a function when the file is fully read from.
Does anyone know?
Thanks

In the comments of Dan's answer, someone gives the answer to your question:
lineReader.on('close', callback);

Related

Is there a way to see how my file was edited - node.JS

I have a file and I am reading it through chokidar. I am also writing to the same file in some another function using fs.writeFileSync.
I want to emit the watcher.on('change') function only when the file is changed manually (i.e. not through WriteFileSync). Is there a way of determining that ?
No, there isn't, not to my knowledge.
You can only know the file was changed, not what process/... changed it.

Configuration file in Azure Functions

I need to read from a JSON configuration file in Azure Function. Is there a way to refer to the file without hard-coding any paths(assuming it's in same directory as the code).
The solution in another answer was something like:
string configuration = string.IsNullOrEmpty(configurationFile) ? "" : File.ReadAllText(Environment.GetEnvironmentVariable("HOME") + #"\site\wwwroot\functionname\filename);
Is there a better way to get this path, or read JSON configuration in general for Azure Function?
Currently, the solution you found is the recommended approach, but with the next release, which is starting to roll out today (5/30/2017), we've introduced a feature to enhance this.
You can learn more about it here:
https://github.com/Azure/azure-webjobs-sdk-script/wiki/Retrieving-information-about-the-currently-running-function
you're able to find out some explanations about this same topic on this another thread, here.
I hope that this information help you.

ApiAxle returning empty result

I am using API Axle for my node API.In that i am following this tutorial http://www.cubrid.org/blog/cubrid-appstools/apiaxle-open-source-api-management-analytics-proxy/.In that after i want to see how many hits for a particular API or particular keys..
For that i am using the following link:
http://127.0.0.1:3000/v1/apis/charts
http://127.0.0.1:3000/v1/keys/charts
But its returning results:{}.PLease help me to solve this.Thanks in advance.
Phil from ApiAxle helped me figure this out. It turns out you need to run apiaxle-proxy with the -q flag, or use their separate queue processor. There is some documentation about this here: https://github.com/apiaxle/apiaxle/blob/4b1a80ef576b3af9511c1239e99841b2d521eb63/proxy/apiaxle-proxy.coffee#L533-538

Inquiry about opening a FIleChannel

Why opening a FileChannel in the following way:
FileChannel.open(path,StandardOpenOption.READ,StandardOpenOption.APPEND);
gives an exception?
I know that it's specified by the API. However I would like to know why it's allowed with the combination of READ, WRITE and it is not with READ and APPEND.
Thanks in advance.
Because it doesn't mean anything. You can't append to a file while only reading from it.

Scheduling mqtt post

I will have a file (text, excel... doesen't matter).
On each line of this file there is date, time, and the code for a function.
What i need is to execute the function written in my file at the specified time and date in node.js on a server.
Since the function is actually a post on a mqtt broker, I'm actualy looking for any method that could do.
Could anyone point me to the right direction?
Thank you
You could use setTimeout to do that.
See the example in this question: Call a javascript function at a specific time of day

Resources