A
A
Alexey Yakovlev2020-03-02 15:21:02
Node.js
Alexey Yakovlev, 2020-03-02 15:21:02

I can’t work with php, an error pops up when I start the server on node, what should I do?

I have a php file in the directory - view/php/signup.php. When I start the server I get an error:

PS F:\Alexey\FriendlyLetter> node server
F:\Alexey\FriendlyLetter\server.js:24
app.set('views', path.join(__dirname, 'views'));
^

ReferenceError: path is not defined
at Object. (F:\Alexey\FriendlyLetter\server.js:24:18)
at Module._compile (internal/modules/cjs/loader.js:1144:30)
at Object.Module._extensions..js (internal/modules/cjs /loader.js:1164:10)
at Module.load (internal/modules/cjs/loader.js:993:32)
at Function.Module._load (internal/modules/cjs/loader.js:892:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47


server.js:

'use strict';

let bodyParser = require('body-parser');
let express = require('express');
let phpnode = require('php-node');

let app = express();
app.engine('php', phpnode);
app.set('view engine', 'php');

let parser = bodyParser.urlencoded({ extended: false });
app.use('/public', express.static('public'));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// Главная страница
app.get('/', function(req, res) {
    res.render('index');
});
// Регистрация
app.get('/sign-up/', function(req, res) {
    res.render('signup');
});
// О нас
app.get('/about/', function(req, res) {
    res.render('about');
});
// Команды
app.get('/teams/', function(req, res) {
    res.render('teams');
});
// Профиль
app.get('/profile/', function(req, res) {
    res.render('profile');
});
app.listen(3000, function() {
    console.log('Подключение');
});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hzzzzl, 2020-03-02
@hzzzzl

well, ReferenceError: path is not defined

const path = require('path')
app.set('views', path.join(__dirname, 'views'));

V
Vitaly, 2020-03-02
@vshvydky

Cannot find module 'php-node'
did you look in the nodemodules, do you have it installed at all? usually the error you show says that the module is not installed

S
Sergey Romanov, 2020-03-02
@Serhioromano

Execute
npm install php-node --save

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question