2017-10-16 80 views
0

您好IM新鲜与编程我开始做我的简单的投资组合中的Heroku 和问题是子页,我不知道如何将新的子页面添加到我的投资组合我总是无法得到/frontend.ejsHeroku的HTML子页面的节点JS

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

我没有约节点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! [email protected] start: `node index.js` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] 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. 
+0

'错误:无法找到模块“express''?尝试'npm install'首先 – dhilt

+0

嘿,当我把npm安装我得到这个答案:npm警告[email protected]没有存储库字段。 –

+0

这没关系......这意味着你不需要在你的package.json中指定一些文件。尝试运行该应用程序。 – dhilt

回答

0

有可能是几个在工作中的问题在这里,第一个和最重要的是,它并不像你的依赖已经安装。您的项目是否包含package.json以及您的所有依赖关系,例如Express? Heroku安装软件包清单中该部分列出的任何内容;请确保也指定您的engines(即节点和版本),以便Heroku知道要使用哪个节点版本。

当您访问您的端点时,请勿在其末尾放置.ejs。 EJS仅用作视图引擎并编译为HTML。

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" 
}