У меня есть простое веб-приложение, и когда я заново его развертываю или выполняю локально, оно работает нормально. Однако, когда я убиваю процесс pm2 и запускаю его снова с
sudo pm2 start /var/www/thewthr.app/index.js --watch -l /var/log/pm2/thewthr.app.log
, это приводит к:
Error: Failed to lookup view "index" in views directory "public"
at Function.render (/var/www/thewthr.app/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/var/www/thewthr.app/node_modules/express/lib/response.js:1012:7)
at /var/www/thewthr.app/index.js:35:9
at Layer.handle [as handle_request] (/var/www/thewthr.app/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/thewthr.app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/thewthr.app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/thewthr.app/node_modules/express/lib/router/layer.js:95:5)
at /var/www/thewthr.app/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/var/www/thewthr.app/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/thewthr.app/node_modules/express/lib/router/index.js:275:10)
Это мой код:
const express = require('express');
const path = require('path');
require('dotenv').config({path: path.join(__dirname, '.env')});
const app = express();
const server = require('http').Server(app);
// start server
server.listen(process.env.PORT, () => console.log(`Express running → PORT ${server.address().port}`));
// start rendering engine
app.set('view engine', 'pug');
app.set('views', 'public');
// define express props
app.use(express.static('public'));
app.use(express.urlencoded({extended: true}));
app.use(express.json());
// render view
app.get('/', (req, res) => {
res.render('index', {
title: `weather ☀`
});
});