在heroku上使用node.js应用遇到麻烦

时间:2019-03-22 14:17:14

标签: javascript node.js 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'

1 个答案:

答案 0 :(得分:0)

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

第二,您不需要正斜杠。

相关问题