Deployment failed in aws beanstalk, getting 502 error - node.js

Everything worked in my local, I googled few questions, all have to do with port problem. But since I'm using express, I think I will not have hardcoded port problem, as you can see below is partially the code in
www
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
I have a app.js and below is my package.json
{
"name": "my app",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
..
..
}
}
What I've tried:
rename app.js to main.js
created nodecommand.config file like someone suggested

Create the .zip from the contents, not create a zip from the parent folder.
Hopefully somebody else will find this helpful!

Related

Error when deploying a node.js app on a PLESK ONYX server with Phusion Passenger V. 5.3.5

I want to deploy a small node.js app on a PLESK-ONYX server - on which Phusion_Passenger / 5.3.5 is also running!
The following happens:
This works here:
var express = require ('express');
var bodyParser = require ('body-parser');
That does not work:
import express from 'express';
import bodyParser from 'body-parser';
The following error then occurs:
The Phusion Passenger application server tried to start the web application through a Passenger-internal helper tool called the "wrapper". But Passenger was unable to execute that helper tool because it encountered an internal error.
The stdout/stderr output of the subprocess so far is:
/var/www/vhosts/hosting13.netcup.net/mem3-s3.hxxx-3.de/index.js:2
import express from 'express';
^^^^^^^
How can one solve it?
Where is the problem?
Thank you for your help in advance!
Best regards
Markus
Hello, I have new findings in the meantime ...
my problem seems to be - that the highest-available node.js version in PLESK at the moment is 12.4!
In PLESK - i must start the node.js-App with a server.js-File - like this:
const app = require('./index.mjs');
const http = require('http');
http.createServer(app).listen(process.env.PORT);
My node.js-Version is V.12.4 so i must use esm like this:
require = require("esm")(module/*, options*/)
module.exports = require("./index.js")
How can i combine the 2 files in the right way?
Thanks a lot for your help!
Here is the content of "package.json":
{
"name": "mb-test-1",
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"type": "module",
"scripts": {
"start": "nodemon -r esm index.mjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv":"^8.2.0",
"esm":"^3.2.25",
"express":"^4.17.1",
"mongoose":"^5.9.29",
"nodemon":"^2.0.7"
}
}
But unfortunately I haven't found yet - where in PLESK the start command for node.js can be edited!
Best regards
Markus
for using import from you should change type in package.json to module so add this code to the package.json
"type": "module"
Note: but export file is different between commonjs and module.
by default type is commonjs , check this article
you can also using babel module, update scripts in package.json like this
"scripts": {
"build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
"start": "npm run build && node dist/app.js"
}
after that for running project
npm start

How do I fix an Internal Server Error?- Google Cloud

I am following this tutorial on Google Cloud Platform and am finding that the SIMPLE app launches successfully up on port 8080 but when I head over to the browser to view it externally, I get an internal server error. The tutorial can be found here:
https://cloud.google.com/appengine/docs/standard/nodejs/building-app/deploying-web-service
I am using Win8.1 using the GCP cloud shell terminal.
I have also tried updating my npm packages, moving my yaml, nodejs files to the next higher directory as well as deleting the package.json in the next higher directory. Like I said, port 8080 can come up and logged to the terminal, but does not come up in the browser. My package.json is as follows:
{
"name": "express",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
My app.yaml file is
runtime: nodejs10
And my server.js file is
//this is a test by MP2
// date of use : 2020-0601
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello from App Engine!');
});
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
Any help would be great since I am new to the google cloud. What is also interesting is that the most current version of express is installed at the next higher folder but not in the current one where the desired JSON is. ( and unable to update it) Thank you.
-MP
It seems that this is because there is no express dependency in package.json:
"dependencies": {
"express": "^4.17.1"
}
I have replicated all steps and it worked. In the tutorial there is 4.16.3 version, I have different, because I have used npm install express -s and it added version automatically to package.json. However it works with 4.16.3 as well on my side.
I hope it will help!

Node failing to deploy due to lack of package.json despite having a valid package file in the zip file

I'm trying to deploy a basic node application but whenever I try to deploy it I get an error saying:
"Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js."
I have tried re-creating the zip file and restarting the node file
I have tried validating my package.json and it is valid
my app.js is simply:
const server = http.createServer( (req,res) => {
res.writeHead(200, {"Content-Type" : "text/plain"})
res.end("Hello World")
})
server.listen(3000)
console.log("Listening on port 3000")
my package.json file is:
{
"name": "Tutorial",
"version": "1.0.0",
"description": "A simple Hello World",
"main": "app.js",
"author": "kittom",
"license": "ISC"
}
It should allow me to see hello world on port 3000 of the url

proxy nodejs express at package.json raised an error on campus network

I work on a project as a fullstack developer on using reactjs & express.
My express server is on server folder, and reactjs client is on server/client.
I set the following proxy at my package.json at my server/client folder which includes ReactJS (create-react-app based). :
"private": true,
"proxy": {
"auth/google": {
"target": "http://localhost:5000"
},
"/api/*": {
"target": "http://localhost:5000"
},
"/apis/*": {
"target": "http://localhost:5000"
}
},
"dependencies": {
When I connect to interent at the university campus I get the following error
but when I connect to internet outside campus no error happens. How can I avoid that from happening?
I really appreciate your help guys. I found that the issue is not related to university network restrictions. I found the main problem, is that express server is not working on the university network, so
npm run server which is "server": "nodemon index.js",
cause an error:
and that what searching for its solution now. You may help me on finding that even by linking to other posts resources.

NodeJS - Deploy socket server in Jelastic

I have a socket server that I want to deploy in my Jelastic NodeJS setup. It is made of 2 files, being server.js the main file, the one started/opened by node, and worker.js the file opened as a child process by the server when required (each child handles a socket).
I never deployed a project via Jelastic or any other cloud PaaS/hosting. How should I proceed to do this?
I know that I have to write the package.json, but that's all I know.
So far, this is what I've got:
//package.json
{
"name": "Myserver",
"version": "1.0.0",
"description": "My Server",
"main": "server.js",
"dependencies": {
"microtime": ">=1.2.0",
"microseconds": ">=0.0.2",
"mysql": ">=2.5.4",
"point-in-polygon": ">=0.0.0"
},
"devDependencies": {},
"scripts": {
"start": "node server.js"
},
"author": "Magister"
}
I searched on their docs but all they have is how to deploy a WEB application, but my server is not web-related, so that information is not relevant.
Any suggestions?
Do you have a public IP? Most likely WebSocket app won't work behind the proxy so far

Resources