Answer the question
In order to leave comments, you need to log in
How to include node.js file in index.php?
There's been a problem. I don't know how to include node.js file in index.php? And I can't access localhost/site/index.php.
Here is the code:
index.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
server.listen(3000);
app.get('/', function (req, res) {
res.send('sad');
});
Answer the question
In order to leave comments, you need to log in
Please clarify why you need to include the node.js file in index.php?
Judging by your code, it will be enough to connect via SSH to the server and go to the folder where server.js is located, type "node server.js &&"
The question is very poorly formulated, it is not clear what task should be implemented in this way.
We take and read how rewrite is configured in nginx and Apache.
If I understood your question correctly:
1. Node AND index.php on the same server
2. You need to read and output index.php when requesting to a node
--
app.get('/', function (req, res) {
fs.readFile('/path/to/index.php', {encoding: 'utf8'}, function (err, data) {
if (err) throw err;
res.send('data');
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question