gpt4 book ai didi

javascript - Node js中的Heroku html子页面

转载 作者:行者123 更新时间:2023-11-28 02:48:48 25 4
gpt4 key购买 nike

你好,我刚接触编程,我开始在 heroku 中制作我的简单作品集问题是子页面我不知道如何将新的子页面添加到我的投资组合我总是得到 Cannot GET/frontend.ejs

链接到我的投资组合: http://poninsky.herokuapp.com

我对 node js 了解不多

这是来自 index.js 的代码,我从 heroku 获得了添加子页面所需的内容:

var express = require('express');
var app = express();

app.set('port', (process.env.PORT || 5000));

app.use(express.static(__dirname + '/public'));

// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.get('/', function(request, response) {
response.render('pages/index');
});
app.get('/frontend', function(request, response) {
response.render('pages/frontend');
});

app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});

谢谢解答!

运行后我得到这个:

module.js:471
throw err;
^

Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/root/Desktop/test/node-js-getting-started
/index.js:1:77)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

npm ERR! Linux 4.12.0-kali1-amd64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run-script" "start"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! node-js-getting-started@0.2.6 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-js-getting-started@0.2.6 start script 'node
index.js'.
npm ERR! Make sure you have the latest version of node.js and npm
installed.
npm ERR! If you do, this is most likely a problem with the node-js-
getting-started package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project
with:
npm ERR! npm bugs node-js-getting-started
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls node-js-getting-started
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean
to install? '
npm ERR! Please include the following file with any support request:
npm ERR! /root/Desktop/test/node-js-getting-started/npm-debug.log
Done.

最佳答案

这里可能有几个问题,第一个也是最重要的是它看起来不像你的依赖项已经安装。您的元素是否有一个 package.json 列出了所有依赖项,例如 Express? Heroku 安装包 list 那部分中列出的任何内容;确保还指定您的引擎(即 Node 和版本),以便 Heroku 知道要使用的 Node 版本。

当您访问您的端点时,也不要将 .ejs 放在它们的末尾。 EJS 仅用作 View 引擎并编译为 HTML。

关于javascript - Node js中的Heroku html子页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46775785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com