繁体   English   中英

在heroku上遇到node.js应用程序时遇到问题

[英]Having trouble with a node.js app on heroku

我想在heroku上创建一个简单的node.js应用程序。 这是app.js:

 console.log("Starting App") const express = require('express') const app = express() const port = 3000 app.listen(process.env.PORT || port, () => console.log(`App listening on port ${port}!`)) app.get('/', (req,res) => { res.sendFile(__dirname+'/public/index.html') }) app.get('/style', (req,res) => { res.sendFile(__dirname+'/public/main.css') }) app.get('/script', (req,res) => { res.sendFile(__dirname+'/public/script.js') }) app.get('/changelog', (req,res) => { res.sendFile(__dirname+'/public/changelog.txt') }) 

这是我的package.json文件:

 { "name": "", "version": "0.0.0", "description": "", "main": "/App.js", "scripts": { "test": "echo \\"Error: no test specified\\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.16.4" } } 

这是我的Procfile:

web: node app.js

我正在通过github将它部署到heroku,每当我运行程序时它都会给我一个错误,说无法找到模块'/app/app.js'可以帮助我吗?

编辑:我已经使所有小写,我仍然得到此错误:错误:找不到模块'/app/app.js'

首先,应用程序的名称区分大小写 - 您在描述中使用app.js,在package.json中使用App.js。 它们应该是一致的,并且约定是小写的。

其次,你不需要正斜杠。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM