JavaScript D3 Data visualization [duplicate] - javascript

I know that D3.js supports loading data files with XHR and JSONP requests.
However in my case, I am going to run .html files by double clicking on them from filesystem, which is going to run it like file://.../foo.html on browser.
Is it possible to load data file (csv or json) within the same directory from computer as foo.html on browser (while not running on http:// but file://)?

The best solution would be to run a server on your computer to make it work.
The simplest way to have a local web server, as explained here is to run this command in the directory where you have your source code:
python -m SimpleHTTPServer 8888 &
Then just load the page http://localhost:8888

You can by disabling the respective security mechanisms in your browser. I think it works in Opera by default, and you can start Chrome with the --allow-file-access-from-files command line flag to allow loading data from file://.

Adding onto Christopher Chiche's answer (I am a new user, can't comment).
For python 3 in Windows, that command does not work. Instead use this one
python -m http.server [<portNo>]
As described here, in python 3
the module SimpleHTTPServer has been replaced by http.server, at least in Windows.

Similar to the python answer from Christopher Chiche above, you can also use the built-in server that comes with various versions of PHP.
php -S localhost:8888 &
This was more useful for me, as my application has hooks to a php back-end script as well as the d3 front-end.

Related

How to make an executable(.exe) that packages a nodejs server? (not UI-centric)

I have implemented a nodejs server that serves incoming requests to use the bluetooth services of the local computer. I want the nodejs server to be packed as an windows executable file so that I can distribute it. People should be able to just install/run that .exe which will install any packages required (if any) and run the server. How to do this?. I saw and tried node-webkit etc., but they are UI-centric, that is it can pack a nodejs application that opens a html page. But I want my server javascript file to be executed, like the way it is done in command prompt : node file-name.js. How to do this?
I've a server running with nodejs and for execute this I use a .bat file.
Create a .bat file
Inside of the file put:
cd path/to/server/
node índex.js
I used JXCore for this task in the past. It basically creates one executable that includes everything.
Unfortunately active development of is halted.
Solution:
You can use nexe for that.
Create a single executable out of your node.js app
Motivation
Ability to run multiple applications with different node.js runtimes.
Distributable binaries without needing node / npm.
Starts faster.
Lockdown specific application versions, and easily rollback.
Faster deployments.

packaging protractor test script and the dependencies into one file

Now I make my protractor to work. Then I have another question: How to package the spec files and all the dependencies into one file, such as rpm or other format, so I can easily install it on another machine to run it? I searched the Internet and found some tools to package the javascript and CSS and images used in web page. But in my case, I only need to package the javascript I write to do the testing to one file.
I appreciate any suggestions.
The short answer is that's not possible.
When you run protractor on a fresh machine you need to have
an instance of selenium-webdriver server running (with all the browsers you want to test)
nodejs
But, assuming that the new computer you run protractor in has nodejs and selenium-webdriver is set up (i.e. either the local computer has it running, or you're testing over network like using saucelabs), then I guess you can zip up the file to send as one file.

Can you run JSNode scripting on standard hosting packages?

I am relatively new to the server-side scripted JSnode environment and I found mixed answers when I was looking online for what is needed to run JSnode on my server. I am primarily looking to replace my PHP with JSnode and I was wondering if I would be able to do that without my host having to install any new server packages. Thank you for the response.
You can't run server side JavaScript that depends on Node.js without the host having installed Node.js.
Node.js itself doesn't have any unusual dependancies. It does require installing on the server though (and it is not a common option for hosting services, I've only used it when I've had root access to a VPS). If you want to interact with it from Apache (for example) you might need to install something along the lines of mod_proxy.
No, there is no way to do it without installing the new server packages.

Running a local server with javascript

I want to create a simple Javascript program with a HTML interface. The program will run in Chrome. I will also use node-serialport and Node.js to comunicate with an Arduino. I have a HTML and JavaScript file done, but I have no clue how to run it, or how to implement Node.js or node-serialport, nor how to "start" the sever. Initially it will only be running locally, but eventually it may become a real sever. For now, how do I run all that locally?
EDIT: I'm using the sample code from http://brandontilley.com/2012/03/02/controlling-an-arduino-from-nodejs.html, with the CoffeeScript converted into JavaScript.
Lucas, glad you found the blog post useful; perhaps I should add this information to it.
Getting the sketch into your Arduino
Just fire up the Arduino application, paste in the sketch code, and hit "Upload." Should be all you need to do here.
Starting the Node.js Server
What operating system are you using this on? Finding out how to access your Arduino microcontroller via node-serialport will differ based on your OS.
In the source code, change the string value of port to be your Arduino's device (once you know it). Also, the script depends on Express and (of course) node-serialport from NPM, so run npm install express serialport in the directory where your JavaScript file is saved. Finally, run the file with node server.js (assuming server.js is the name of your file). Then you can access the server at http://localhost:8080.
You can use node.js to serve up HTML with Express. If your main Javascript file is called server.js, then run it by typing:
node server.js
at the command line.

Script/App that automatically compiles and compresses js files as you save

I'm building a web site and have multiple js files all in one directory. When I save any one of the js files I want a script to run that will compile and compress all files using the google closure compiler jar.
Example from Google Closure Compiler README:
java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
Is there a shell script or app that does this? I'm looking for something similar to how http://incident57.com/less/ works for CSS.
In linux you can use the inotifywait command to listen for changes in a specific folder.
This script can you give an idea:
#!/bin/bash
directory=$1
inotifywait -q -m --format '%f' -e modify -e move -e create -e delete ${directory} | while read line
do
echo "doing something with: $line";
# for example:
# java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
done
You can invoke this script specifying the "monitor" directory, in this way
./inotify.sh ~/Desktop/
Linux and Mac OSX have application interfaces that let you monitor filesystem changes.
I'm myself using linux so I'm familiar with inotify. Doing a script that compresses your files would be easy enough that I could do it for you from a feasible price.
For Mac OSX you can use FSEvents to get a same effect. Though you'll need to do it yourself.
If you wonder how to do this on windows.. Well nobody in his full senses would be using that system for software development.
If you use some eclipse-like IDE, you can create and set builder for this.
But your project should also has "Build Automatically" checkbox.
Fileconveyor is a Python script that watches and processes files, and can even upload them automatically.
I'd recommend checking out the website to see if it's something that might help you: http://fileconveyor.org/

Categories

Resources