简体   繁体   English

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

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

I am trying to create a simple node.js app on heroku. 我想在heroku上创建一个简单的node.js应用程序。 Here is app.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') }) 

here is my package.json file: 这是我的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" } } 

and here is my Procfile: 这是我的Procfile:

web: node app.js

I am deploying this to heroku via github, and whenever I run the program it gives me an error, saying Cannot find module '/app/app.js' can anyone help me with this? 我正在通过github将它部署到heroku,每当我运行程序时它都会给我一个错误,说无法找到模块'/app/app.js'可以帮助我吗?

Edit: I have made everything lowercase and I still get this error: Error: Cannot find module '/app/app.js' 编辑:我已经使所有小写,我仍然得到此错误:错误:找不到模块'/app/app.js'

First, the name of the app is case sensitive - you use app.js in your description, and App.js in your package.json. 首先,应用程序的名称区分大小写 - 您在描述中使用app.js,在package.json中使用App.js。 They should be consistent, and the convention is lowercase. 它们应该是一致的,并且约定是小写的。

Second, you don't need the forward slash. 其次,你不需要正斜杠。

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

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