Hi all,
I have a very basic express server setup using node. Works fine locally using Heroku local web. The problem occurs after it is deployed to Heroku. It appears to be stuck on the build phase where it listens to the port indefinitely and timeout using the nodejs default buildpack.
my file structures are:
-public
-css
-style.css
-index.html
-index.js
-package.json
-Procfile
Index.js
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
const app = express();
app
.use(express.static(path.join(__dirname, 'public')))
.get('/', (req, res) => res.send(path.join(__dirname, 'public', 'index')))
.listen(PORT, () => console.log(`listening on port <<${PORT}>> ----`));
package.json
{
"name": "hello-world-express-static",
"version": "1.0.0",
"description": "express server used to render html hello world page with use of JS",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "mocha ./test",
"build": "node index.js",
"deploy": "node index.js"
},
"keywords": [ "node", "heroku", "express" ],
"devDependencies": {
"mocha": "^8.1.3",
"supertest": "^4.0.2"
},
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1"
},
"engines": {
"node": "12.x"
},
"repository": {
"type": "git",
"url": "https://github.com/winstoncwang/Sandbox/tree/master/hello-world-express-static"
}
}
Procfile
web: node index.js
Build log
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 12.16.2
engines.npm (package.json): 6.14.4
Resolving node version 12.16.2...
Downloading and installing node 12.16.2...
npm 6.14.4 already installed with node
-----> Installing dependencies
Installing node modules
> nodemon@2.0.3 postinstall /tmp/build_9cef07c9_/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
added 198 packages in 3.344s
-----> Build
Running build
> ecommerce-project@1.0.0 build /tmp/build_9cef07c9_
> node index.js
The app is running on port: 5000
-----> Timed out running buildpack Node.js
Terminated
! Push failed
Link to my Github repo:
[https://github.com/winstoncwang/Sandbox]
Thank you for taking the time to go through all of this. Any help is appreciated.