简体   繁体   中英

Having trouble with a node.js app on heroku

I am trying to create a simple node.js app on heroku. Here is 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:

 { "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:

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?

Edit: I have made everything lowercase and I still get this error: Error: Cannot find module '/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. They should be consistent, and the convention is lowercase.

Second, you don't need the forward slash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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