NodeJs talks to ubuntu server on EC2 - javascript

Recently I have installed a nodejs app on my EC2 directory, listening to one of the port from EC2 instance. I also have a couple of executable python scripts on my EC2 ubuntu Linux server.
The way I run those executable python script is to use putty and connect to ubuntu via command line( for windows, Sure for Mac I use terminal). I am just wondering, is it possible to have the nodejs app does the same job, so I will have a UI based on the web app, which can talk to ubuntu and execute those scripts (python scripts such as "python run.py".
Please advice, thank you!

If I'm understanding correctly, the Python scripts are on the same server as the Node app, and you'd like to run them from Node.js
var execScript = require('child_process').execFile;
execScript('/path/to/python/script.py');
Should probably do the trick.
Can also add options or callbacks as needed, see the docs here: http://nodejs.org/api/child_process.html

Related

Testing a Single Page Application while simulating the backend

I have a single page application developed using javascript, react and redux that communicates with the backend via web socket, rest and json.
I wish to explore the possibility of working independently of the backend, both as I develop and in terms of treating the front end as a subsystem and performing subsystem tests on it.
Is this a good approach? What tools would you recommend? For example, I have used selenium previously with python. Would it be a sensible option for me to write my own simple test environment using a selenium api where tests are configured in their setup to respond to rest requests from the front end in the appropriate manner. Maybe there are better approaches.
I think npm provide http-server
You can run server in your project dir and it should be server on localhost.
But if you are using Linux or Mac, the easiest way will be:
$ cd you_app_folder
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
As python is built in on mac and Linux it is easiest way as I said.

Serving locally a webapp

I'm developing an html web page which will visualize data. The intention is that this web page works only on one computer, so I don't want it to be online. Just off line. The web uses only Js, css and html. It is very simple and is not using any database, the data is loaded through D3js XMLHttpRequest. Up to now it is working with a local python server for development, through python -m SimpleHTTPServer. Eventually I will want to launch it easyer. Is it possible to pack the whole thing in a launchable app? Do you recommend some tools to do it or some things to read? What about the server part? Is it possible to launch a "SimpleHTTPServer" kind of thing without the console? Or maybe just one command which launches the server plus the web?
Thanks in advance.
Update
Save and compile following file in your folder.Double click on .pyc file to run it.
import SocketServer
import SimpleHTTPServer
import webbrowser
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
webbrowser.open(<yourip:PORT>)
This should work on all platforms
Put the following into a text file and save it with extension .bat
cd yourfolder
python -m SimpleHTTPServer port
C:\>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "yourip:port" --new-window
This should work fine in windows
For Mac
cd yourfolder
python -m SimpleHTTPServer port
open -a "Google Chrome" --args --kiosk http://google.com
and save with extension .command
Not too sure what you are trying to achieve from reading the question. but from what i understand is that you'd like to be able to launch your application and serve it on the web when done.
you could use heroku!(www.heroku.com), same way you are hosting the application on your local, you simply make a Procfile, and in that file you put in the command that you'd normally run on your local, and push to Heroku.

Is there a way to run a Node.js application within a Tomcat server?

I have a REST Web Service running within Tomcat and I do not want to run the Node.js application manually. Can I somehow run my Node application using Tomcat?
You cannot run Nodejs server inside tomcat.
I would suggest to ge to http://nodejs.org/ and read some docs and refer some videos.
I have used openshift to host my node js application
please refer this link to know more about where to host nodejs application

How to use a browser on a remote server for an automated tests

I inherited a project where the person wrote tools to test our site's UI using JQuery and JS.
I don't know too much about it other than it requires a browser to be spawned and I think the tool uses JS to interact with iframes to see if it's the expected values.
My job is to get this tool to run on a remote server and post the results to Jenkins.
The remote test server and staging server is linux. From our staging server, I want to write a script to spawn a browser and run cmds from the tool to test our UI. I ran the following manually:
ssh -X user#remote_test_server /usr/bin/firefox
However, the remote server says:
Error: no display specified
Is there a way to spawn a browser for automated testing from one headless server to another? Thanks in advance for your help.
I faced a similar problem when I tried to automate a GUI installation program. While there are quite some different possibilities to choose from (e.g. Xnest, Xephyr?), I ended up using vncserver, because it's relatively easy to debug the GUI session this way.
You need to create a vncpassword file, I think:
mkdir -p $HOME/.vnc
chmod 0700 $HOME/.vnc
echo MyLittlePassword | vncpasswd -f > $HOME/.vnc/passwd
chmod 0600 $HOME/.vnc/passwd
Starting the server is then quite straightforward
vncserver
export DISPLAY=:1
/usr/bin/firefox&
...
Now it is possible to connect to the VNC server with a VNC viewer of your choice. But beware there may be no window manager, depending on the X startup scripts of your environment.
Shutting the server down
vncserver -kill :1
In the configuration of Jenkins project , specify the
Build Environment
Start Xvfb before the build, and shut it down after.
#

Installing NodeJS and SocketIO in a Remote Server

My project is a Real Time Two-Player Facebook Game, and what I need is a tool that will help me build the game with quick responses to enable the "Real Time" function of the game. I have just found out about the Node JS and Socket IO. I have some knowledge in JavaScript so I stepped up and watched a few tutorials that discuss the functions of Node JS and Socket IO.
Here's the link to the videos that I have watched:
http://www.youtube.com/watch?v=mSE6xHkcX0w
I understand the basic of the Node JS and Socket IO and successfully installed it in my localhost. The problem is when I uploaded the files from my localhost to my remote server, some functions of the program are not working well. I don't know how to node my JavaScript file when it is on the server, because if it's in my localhost, I am using command prompt to run it.
node app.js
Node is not a web framework.
Chances are, you're using a web host that's generalized for web frameworks like PHP and Ruby on Rails. You're going to need virtual private server hosting, or Node-specific hosting, because Node requires a virtual machine to run. You otherwise won't be able to run Node Package Manager or Node itself.
Joyent has provided a list of hosts here.
If you chose to use a VPS or dedicated machine, an installation guide would be found here. This is how you would install Node on CentOS.
wget http://nodejs.org/dist/v<version>/node-v<version>.tar.gz
tar -zxf node-v<version>.tar.gz
cd node-v<version>
./configure
make -j <number of cores>
make install

Categories