问题
I am deploying my node.js application on heroku but when i run my app it shows me Application error and when i check my logs file i found NPM_CONFIG_LOGLEVEL=error
My package.json file is:
{
"name": "wework-1",
"version": "1.0.0",
"description": "We Work Meteor, a job board and developer directory for Meteor specific work https://www.weworkmeteor.com",
"main": "",
"engines": {
"node": "= 4.5.0",
"npm": "= 3.9.6"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint .",
"pretest": "npm run lint --silent"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rohitchaudhary701/wework-1.git"
}
}
My logs file is:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): = 4.5.0
engines.npm (package.json): = 3.9.6
Resolving node version = 4.5.0 via semver.io...
Downloading and installing node 4.5.0...
Resolving npm version = 3.9.6 via semver.io...
Downloading and installing npm 3.9.6 (replacing version 2.15.9)...
-----> Restoring cache
Loading 2 from cacheDirectories (default):
- node_modules
- bower_components (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json)
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
-----> Build succeeded!
! This app may not specify any way to start a node process
https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 12.7M
-----> Launching...
Released v6
https://whispering-cliffs-66861.herokuapp.com/ deployed to Heroku
App url is https://whispering-cliffs-66861.herokuapp.com/
回答1:
From your logs:
This app may not specify any way to start a node process
You probably need to do two things:
- add
start
script inpackage.json
- make sure you listen on the port in
process.env.PORT
Take a look at this example:
- https://github.com/rsp/node-live-color
See package.json and the start
script:
"scripts": {
"start": "node server.js"
},
See:
- https://github.com/rsp/node-live-color/blob/master/package.json#L6
And see the port number initialization:
const port = process.env.PORT || 3338;
// ...
server.listen(port, () => {
console.log(`Listening on http://localhost:${port}/`);
});
See:
- https://github.com/rsp/node-live-color/blob/master/server.js#L13
- https://github.com/rsp/node-live-color/blob/master/server.js#L46-L48
If you want easier deploy with Deploy to Heroku button then you may also need an app.json
file:
- https://github.com/rsp/node-live-color/blob/master/app.json
But for manual deploys you should only need a start
script in package.json
so that you app could be started with npm start
and your app needs to take the port to listen to from the PORT
environment variable.
You can test it with locally running:
PORT=2255 npm start
and making sure that you can access your app on http://localhost:2255/ for this and any other port you specify. If you cannot start your app with the above command then your app is unlikely to run on Heroku. You could also have a Procfile presend but without it you should at least have npm start
working, see:
- https://devcenter.heroku.com/articles/procfile
- https://devcenter.heroku.com/articles/nodejs-support
回答2:
You seem to be trying to deploy a Meteor app to Heroku.
Heroku is not as integrated with Meteor as Galaxy is, or as Modulus / Xervo used to be.
Heroku will detect a node-like app, but you will need first to convert your Meteor app into a Node.js app, typically using meteor build
command and uploading the resulting server bundle, or using some MUP thing.
A simple alternative is to use a 3rd party Buildpack, which will do the conversion for you once you upload your Meteor app to Heroku.
You will find plenty resources for that on the above link or here on SO.
See for example: Heroku errors with Meteor 1.4.1.1
Note: the NPM_CONFIG_LOGLEVEL=error
line is a setting, not an actual error…
回答3:
What does your Procfile look like? Make sure you don't have web: node app.js in the Procfile. I had the same error and didn't need to use the Procfile. Once I removed it started working.
回答4:
For me, it turned out i required a package that was not in my package.json (dependency), when I added it, the application started working.
来源:https://stackoverflow.com/questions/43687489/deploying-node-js-app-to-heroku-error-npm-config-loglevel-error