I need to host node js through python
<pre><code>var util = require('util'); 
var exec = require('child_process').spawn; 
var run = exec('/usr/bin/python', ['-m', 'SimpleHTTPServer', '9002']); 
run.stdout.on('data', function(data){ 
    console.log('stdout: ' + data.toString()); 
    }); 
run.stderr.on('data', function (data) { 
    console.log('stderr: ' + data.toString()); 
    }); 
</code></pre>

<p>test.py</p>

<pre><code>from bottle import route, run, template

@route('/hello/&lt;name&gt;')
def index(name):
    return template('&lt;b&gt;Hello {{name}}&lt;/b&gt;!', name=name)

run(host='localhost', port=9002)
</code></pre>

<p>I am new to node js and python just i want do communicate between node js to python with localhost. A simple python script with localhost url to hit node js url after running node js scrpit whih call python script in node and host the same on web browser.</p>

<p>Not entirely sure I see the problem. Your code works. </p>

<p>1) Make sure you access <code>localhost:9002</code><br>
2) If you meant to run your bottle code, then use </p>

<pre><code>var run = exec('/usr/bin/python', ['/path/to/bottle_server.py']);
</code></pre>

<p><a href="http://i.stack.imgur.com/EEGKK.png" rel="nofollow"><img src="http://i.stack.imgur.com/EEGKK.png" alt="img1"></a></p>

<p>As for communicating back and forth between the Python code and the Node.js code, then you need sockets. Some libraries to look at could include <code>socket.io</code> or use a messaging queue like <code>zmq</code>.</p>

<p>If you want one-way communication to your python API, then you need to perform HTTP requests to <code>http://localhost:9002</code> from the Node code. Alternatively, Node is very much capable of the same functionality you've included in the Python code on its own.</p>

<p><strong>EDIT</strong></p>

<p>Regarding below comments, here is an updated script. You need to <code>inherit</code> the parent's <code>stdout</code> and <code>stderr</code>, otherwise, as you see in the image above, it thinks python is printing to <code>stderr</code></p>

<pre><code>var util = require('util');
const spawn = require('child_process').spawn;

var run = spawn('/usr/bin/python', ['-m', 'SimpleHTTPServer', '9002'],
    { stdio: ['ignore', 'inherit', 'inherit' ] });

run.on('exit', (code) =&gt; {
  console.log(`Child exited with code ${code}`);
});
</code></pre>

<p><a href="http://i.stack.imgur.com/egaQf.png" rel="nofollow"><img src="http://i.stack.imgur.com/egaQf.png" alt="img2"></a></p>

python node.js client-server