V
V
Vadim9972014-12-22 20:46:22
PHP
Vadim997, 2014-12-22 20:46:22

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>

server.js
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

3 answer(s)
D
Denis Smirnov, 2014-12-22
@Groov3

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 &&"

Y
Yuri Yarosh, 2014-12-22
@voidnugget

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.

I
index0h, 2014-12-23
@index0h

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 question

Ask a Question

731 491 924 answers to any question