【问题标题】:Heroku html subpages in node js节点js中的Heroku html子页面
【发布时间】:2018-03-28 07:08:31
【问题描述】:

您好,我刚开始编程,我开始在 heroku 中制作我的简单作品集 问题是子页面我不知道如何将新的子页面添加到我的投资组合中我总是无法获取 /frontend.ejs

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

我没有太多关于node js的知识

这是来自 index.js 的代码,我从 heroku 得到什么我需要 chenge 来添加子页面:

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.

【问题讨论】:

  • Error: Cannot find module 'express'?先试试npm install
  • 嘿,当我输入 npm install 我得到这个答案:npm WARN node-js-getting-started@0.2.6 No repository field.
  • 没关系......这意味着你没有在你的package.json中指定一些文件。尝试运行应用程序。

标签: javascript html css node.js heroku


【解决方案1】:

这里可能存在几个问题,第一个也是最重要的问题是它看起来不像您的依赖项已安装。您的项目是否有 package.json 列出了所有依赖项(例如 Express)? Heroku 安装包清单的该部分中列出的任何内容;确保还指定您的 engines(即节点和版本),以便 Heroku 知道要使用的节点版本。

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

【讨论】:

    【解决方案2】:

    是的项目有 package.json 在里面:

    {
    "name": "node-js-getting-started",
    "version": "0.2.6",
    "description": "A sample Node.js app using Express 4",
    "engines": {
    "node": "6.11.1"
    },
    "main": "index.js",
    "scripts": {
    "start": "node index.js",
    "test": "node test.js"
    },
    "dependencies": {
    "ejs": "2.5.6",
    "express": "4.15.2"
    },
    "devDependencies": {
    "request": "^2.81.0",
    "tape": "^4.7.0"
    },
    
    "keywords": [
    "node",
    "heroku",
    "express"
    ],
    "license": "MIT"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-02
      • 2018-09-03
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 2016-08-02
      相关资源
      最近更新 更多