I am trying to run php code in Node.js. But while typing localhost:4000 in the browser the whole code of index.php is getting displayed in the browser.
Node.js code
var http = require('http'),
fs = require('fs'),
var app = http.createServer(function (request, response) {
fs.readFile("index.php", 'utf-8', function (error, data) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write(data);
response.end();
}); }).listen(4000);
PHP Code:
<?php
$handle = fopen("data.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
echo $line;
echo '<br>';
}
} else {
// error opening the file.
}
fclose($handle);
?>
So , please let me know , how can i run PHP code through node.js , suggest me some solution.