How to read contents of an SQL file in NodeJS? - javascript

I want to read the contents of an SQL file in NodeJS. Is there a simple way to do this? Even just to import the whole file as a string somehow would be good. It seems like a basic thing but I can't find any information on how to do it.
Any help would be greatly appreciated.

It turns out you can simply use
fs.readFileSync("file_name.sql").toString()
in the same manner you would a .txt file.

you can try use XMLHttpRequest to import the file as a string.
https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest

Related

Polymer 2.0 - Can you write to fs?

I'm working on an MVP for a project, and I'm trying to mock up a "database" quick and dirty. I thought for now I'll just put my "database" into a .json file and work with that. I am able to use iron-ajax to get a file read in to a Polymer property to be manipulated, however, I don't know how I could write it back onto the filesystem once I manipulated it. I tried
let fs = require('fs');
fs.writeFile('./db/db.json', json, 'utf8');
However, this does not work (apparently, require does not work on the client side). I've tried googling around and checking the answers on the linked thread, but the answers are quite vague ("use <script> tag" - okay, but how?) and I haven't been able to figure it out. How would I be able to pass a json object and write it back to the filesystem?
Simple answer is no you can't. You have to write a little backend for that but for that i usually use the localStorage there you can store JSON and read write.

Javascript and SOAP (CUCM)

I'm using this code (http://blog.darrenparkinson.uk/2014/04/accessing-cisco-administrative-xml-axl.html) to make connection with CUCM.
But, this code returns the XML in console. I need a XML file or .CSV file for open in Excel.
How can I do this?
Tks
Are you trying to get a list of all the Route Patterns on the Call Manager? etc. I guess this should help:
https://medium.com/#chandupriya93/xml-to-excel-conversion-using-node-js-d70296ba3bea
This uses an xml2js and json2xls module to parse the XML file into a JSON file and finally convert into XLS.
Hope this helps.
Ank
Another choice is camaro. You can take the element you want as an array easy. then convert that to csv
You can see the sample in that package

Importing a file in JavaScript (not browser or HTML)

I know it seems like this question may exist elsewhere, but I haven't been able to find a solution for purely JS as a scripting language.
Is there a way for me to import a file (locally or url) like a .csv that I can then operate on?
I'm looking for a purely javascript solution, without HTML or jQuery.
for example, if there was a file called example.txt on your computer with the line "this is an example file, can you import this text?" and you had to print the 4th word in the file, how would you do that with only JS?
Or a .csv that you needed to read off you computer and return a json object of, how would you read in that CSV?
Thanks in advance for any help!

Load a JSON file from a URL without AJAX request?

So I can't seem to find an straight answer to my problem.
What I want to do is load a JSON file that's located on a specified URL. It's a large complicated JSON file. Basically, I've been trying to use AJAX to 'get' the file all night long. I've used the $.getJSON Jquery shortcut too, without any luck. I believe the server isn't allowing for AJAX requests, but if I enter in the URL I can access the file without a problem.
My question is, is there any way I can get the file so I could use it in order to create this little mock up site that I need to create?
Is this possible?
I've tried looking for a way to just rip the text off of the URL and then just turning that into a JSON file so I could parse it, but I haven't found any relevant information on this tactic.
If you have any ideas, please let me know, thank you! :D

Looking for suggestions. Javascript object data to xls

I´ve a Javascript object with all the data that I need to store on xls file. What could be the better way? Apache POI? Jasper-Reports? I´m not sure about the correct choice.
Thanks!
If you just need to import it with Excel I would suggest creating an CSV file out of the data instead.
This can easily be done with JavaScript and Excel can import that format.

Categories