I just use eb deploy and also tried upload with zip, the elatic beanstalk environment show "degraded".
The log when I click in to see is
Overall
Degraded
Impaired services on all instances.
Severe
Following services are not running: web.
My app.js file:
const express = require('express');
const app = express();
app.listen(3000, () => {
console.log("Sever console log.")
});
package.json content
{
"name": "project_api",
"version": "1.0.0",
"engines": {
"node": "12.18.3"
},
"description": "the server side of the api",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Businsoft Limited",
"license": "ISC",
"dependencies": {
"dropbox": "^5.2.1",
"express": "^4.17.1",
"isomorphic-fetch": "^2.2.1",
"nodemon": "^2.0.4"
}
}
I think this is the simpliest start with Elastic Beanstalk, but somehow it fails. Any idea to solve it?
After debug for a while, I managed to figure out the issue.
In package.json
I need to remove this line:
"main": "app.js",
And the add the "start" in the "scripts" like this:
"scripts":
"start": "node app.js"
And then update the
app.listen(3000, () => {
console.log("Sever console log.")
});
to
const port = process.env.port || 3000;
app.listen(port, () => {
console.log("Sever console log.")
});
And then go to AWS Console > Elastic Beanstalk's environment > Configuration > Software Edit > add a properties at Environment properties
Name port Value 8080
Finally reupload the source code, and it works.
Related
I'm using Windows and I've just installed nodemon 2.0.12 (added to path). Whenever I run a basic application it works it should until I save a file, then I receive the following error
My project is a basic express app:
const express = require('express')
const app = express()
const PORT = 3000
app.use("/", (req, res) => res.send('test'))
app.listen(PORT, function() {
console.log('Server started on port 3000')
})
My package.json is as follows
{
"name": "express.1",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"dev": "nodemon app.j"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.12"
}
}
What might be the reason for this?
Downgrading Nodemon to v2.0.7 seems to work. I don't understand why it broke in the first place.
index.js
// create an express app
const express = require("express");
const app = express();
// use the express-static middleware
app.use(express.static("public"));
// define the first route
app.get("/", function (req, res) {
res.send("<h1>Hello World!</h1>");
});
// start the server listening for requests
app.listen(process.env.PORT || 3000, () => console.log("Server is running..."));
package.json
{
"name": "SimpleApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
},
"engines": {
"node": "10.x",
"npm": "*"
}
}
Procfile
web: echo "I don't want a web process"
service: npm start
I have deployed it in heroku.
And the logs are showing as below
2021-06-22T13:16:11.346614+00:00 app[service.1]: ------------------------------------------------------------------
2021-06-22T13:16:11.371025+00:00 app[service.1]: Server is running...
But i am getting application error when i try to load the page.
It is working fine in local
Your web dyno maybe turned off by default.You need to turn it on inorder to run your heroku app
When declaring the middleware check whether that directory you have set is correct
app.use(express.static("public"));
If not then use __dirname to concatinate the correct directory like so
const public = path.join(__dirname, "../public")
then
app.use(express.static(public));
I have added node_modules in .gitignore that's not issue!
How to solve this errors because in engines I have specified version of both.
Here is Code :
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node":"12.6.2",
"npm":"6.14.4"
},
"scripts": {
"start": "node index.js"
},
"author": "smeet_kothari",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
and this is my index.js file
And Code of index.js file.
const app = express();
app.get('/', (req,res) => {
res.send({hi:'there'});
});
const PORT = process.env.PORT || 5000;
app.listen(PORT);
G:\01) Web Development\10) nodejs project\[FreeCourseSite.com] Udemy - Node with React Fullstack Web Development\MailFeed\server>heroku -v
heroku/7.47.7 win32-x64 node-v12.16.2
Procfile has been added too!
Thanks for solution in advance!
Seems like you have not defined Procfile for the project try it first if still not solved comment the total error appearing in the command line
Azure deployed this app with successfully flag, but homepage response with 500 status
index.js:
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello!");
});
app.listen(3000, () => console.log("Hwllo!"));
package.json:
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Have you tried setting the variable process.env.PORT for handling the named pipe port in Azure App Service. See Listen additional port Microsoft Azure Nodejs.
If it does not solve your issue, try to go through KUDU console and look for the particular erros.
I want to deploy my server on Heroku, but on Heroku build it says this:
The app works fine locally, but somehow it crashes on the Heroku server.
This is the file structure
This is the code for server.js
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('data.json');
const port = process.env.PORT || 4000;
server.use(router);
server.listen(port);
This is package.json
{
"name": "server",
"version": "1.0.0",
"description": "json-server",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm install && node server.js"
},
"author": "japsuchiha",
"license": "ISC",
"dependencies": {
"core-util-is": "^1.0.2"
},
"devDependencies": {
"json-server": "^0.15.1"
}
}
Pure guess, but I don't think heroku is installing json-server since it's listed under devDependencies