簡體   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