节点js中的Heroku html子页面

时间:2017-10-16 17:21:54

标签: javascript html css node.js heroku

你好我很新鲜的编程我开始在heroku中创建我的简单组合 和问题是子页面我不知道如何添加新的子页面到我的投资组合我总是得到不能GET /frontend.ejs

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

我不太了解节点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.

2 个答案:

答案 0 :(得分:0)

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

访问终端时,请不要将.ejs放在最后。 EJS仅用作视图引擎并编译为HTML。

答案 1 :(得分:0)

是项目的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"
}