Saving javascript script output to file on server - javascript

So far Gurus here helped me a lot so far and I am back again with my little queries again.
I have a js that is being called from a webserver through a internal site I am taking care of. js has lots of very helpful debugging comments through
console.log($output)
that are being displayed on the console. I was wondering if there is any way i can redirect these comments to a log file on server.
I know it is hard but not impossible... I thought of doing something like
> exec 1>>${LOG_FILE}
but then it means it will get outputs from every file will be going to that file.
I only need the output from one file... is it possible?? plus do I need to run it through cron? because I don't have permission to change anything in js itself.
-Thanks

Related

How to I turn a python script into a web app?

Sorry for the noob question, but I created a script that web scrapes data off our sccm server and compares it to programs that need to be pushed to hostnames.
My script works perfectly when I run it in pycharm, but I would now like to make this program available to the other guys on my team via webpage, instead of them needing to borrow my computer everytime, LOL!
Is there a way I can use a javascript front end to let them enter their username, password and serial number, and than based off that info run my script?
I'm not a programmer to be honest so I apologize if this seems like a straightforward thing.
This would be difficult for someone to just 'answer' but maybe a rough outline could help?
I'm certainly no professional but this is the way I might approach the issue.
create HTML/CSS/JS front end page with a form
upon clicking the 'submit' button have the JS take form data and export it into a JSON (just did a quick search on 'execute python script on button click' and things like that to find some implementations of the idea)
pass the JSON from the page onto the server and have the python script open up the JSON for the arguments it needs to use
python 'wraps' the results up into a JSON file and gives it back to the front end where you have another JS script that unpacks the JSON file and gives it to the user requesting the info. Alternatively, you could have Python put the data into some sort of excel sheet or csv or whatever and have python email the results to the user.
Once all done you'd simply have an instance of Python and all the appropriate libraries sitting on the server ready to use. Pycharm is simply an editor for code. You could theoretically install python itself, and the appropriate libraries needed for your code and just give your folks the .py file itself and have them run the script out of CMD/Terminal and achieve the same result.
Like I say, no professional by any means, and I'm sure I skipped a couple steps but that's a general outline. Obviously in the forms you'd wanna have validation and such to make sure the appropriate data gets used to avoid errors.

Why is Node Express Duplicating Static Content

I have the following app.js file:
https://gist.github.com/manifestinteractive/393a4aae0c4ed4fb6bc2
When I look at files I am loading statically in the public folder via the operating system, they look correct, however, if I go to view them via the browser as intended for delivery through node express engine, the contents are duplicated. Basically, it is taking the file and appending it to itself, which of course breaks the javascript.
Anyone know why this would be happening? Suck a weird bug and I can't for the life of me put my finger on the cause.
For the record, I have tried looking everywhere for a solution. I've just not seen anyone talk about it. A quick test shows that I can manually change the JavaScript file at the source, and refresh the code in the browser, and it will reflect the changes correctly, but it will still be displayed twice.
Thought it might be some weird issue where maybe I had multiple instances of Node running or something, as that MIGHT explain it... but nothing :(
If I find what it is, I will follow up with the issue immediately, but for the time being, I am likely just doing something stupid someone here might yell at me for... and I would gladly welcome it :)

Run a php file contain javascript from cron job

I tried many online methods people have suggested and still not reached a solution
i need to run a php file that contain javascript from cronjob
For now, I can not do it through PHP
If anyone has an idea I'd love to read
You will probably have to trigger it through a browser. Get a computer to open the URL via the cron tab (or some other timed device... I know you can do it through Automator/AppleScript on a Mac).
How I do it: I split the job in to tasks.
Task 1: Execute Javascript
Javascript would require a browser to run. In this respect you can try casperjs/phantomjs. You can create a a cronjob for this easily. Please check: Running a casper.js script from cron
Task 2: Deliver results to PHP
I assume that you take the results of the JS and use it in the PHP. So JSON can do the job. At the end of the first task output to a file. In this task, read it using file_get_contents.
Task 3: PHP Cron
It is obvious :)
Sure that there are better, easier and simpler solutions. I am a newbie also here, but this method all my problems for a similar work.

How do I read from external files in JS Bin?

I've been doing Code Year at Codecademy and I wanted to start practicing Javascript for myself, but I've been having a tough time figuring out some basic issues.
For my first project, I want to read in from a spreadsheet. I can't figure out how to access the data from its original source online, so I thought I would just save it as a text file. My question, then, is how to read from that.
So it looks like you can't read local files in Javascript. (Although apparently that's changing with HTML5? I don't have any familiarity with that.) So do I have to upload the text file someplace? Can I upload files to JS Bin? If not, does anyone have any recommendations for where I can upload the text file? And either way, once I do, what's the code to read from it?
Thanks in advance. I am sure this question is riddled with misstatements and improprieties, but I've spent a significant amount of time on this and I can't find anything that seems to answer my question. I honestly thought it would be something simple, like "var inputfile = c:\file.txt" but that seems not to be the case. I am totally lost. Thanks!
You can't. File system and storages in Javascript (or rather the client) is sandboxed.
That means you can only read what is written there in the first place. This has to do with security.
You will need to drop (or select) the local files into the browser and have some mechanism there to receive the drop/selection and store the file to one of the local storing mechanisms such as indexedDB or file API (the latter currently only supported in Chrome). For text files localStorage works fine too.
Resources:
http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side
http://www.w3schools.com/html/html5_webstorage.asp
http://www.w3.org/TR/webstorage/
http://www.w3.org/TR/FileAPI/
http://www.w3.org/TR/IndexedDB/
The other option is to upload it to server and download it from there when you need it.
When you get to this point in your development, its time to run your own webserver for testing as it makes things much easier. If you must insist on doing it your way, uploading the file to a file hosting site and reading it in is still possible. Codecademy is great for getting started, but when you get into dealing with persistent data sources (either files or databases) its time to get web hosting or set up your own test server.
Even then you don't REALLY need your own test server, just a folder on your computer. You can access the files with File://, and link in the file you want to read as a relative path. If the .txt file is in the same directory, you just link it in as "Example.txt" when you open the html file in that directory.

What is the typical process with filegroups in chirpy

I have a filegroup configured with Chirpy:
<FileGroup Name="1.min.js" Minify="False">
<File Path="test/temp1.js" />
<File Path="test/temp2.js" />
</FileGroup>
Now I set my master page to download this script 1.min.js. So far so good but the problem is when I edit some of the script in temp1.js, I have to come in this mash.chirp.config and save this file too for 1.min.js to take updated changes from temp1.js. This is tedious for me. If I forget to save at both place it causes countless minutes to figure out why is it not worknig. Is there any better approach to this?
I feel your pain and have had the same issues. Basically, the way I resolved this is to just tell the page to load the JS file directly. This seems to also play well with the js debugger because the files haven't been minified to a single line.
Then after the js file is complete, I add it to my mash.js.chirp.config file to be combined and minified. I know it's not the answer you were hoping for, but despite having to process it in this manor during development, the payout in the end feels worth it to me.
If you really wanted to force it, you could add code to the web projects properties, in the after build command line to invoke the chirpy console to compile this file. I've used the code for this before, but couldn't find it right now. Some info is here though; Oh and I wouldn't name your file .min.js unless you set minify = true. It could come back to bite you later on if you forget you did that.
I found the link to force the compiler;
http://www.annhoang.net/twitter-bootstrap-in-visual-studio-2010-with-chirpy-and-dotless/

Categories

Resources