NodeJS - Deploy socket server in Jelastic - node.js

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

Related

React/Express app not using proxy in package.js

Creating my first React (frontend)/Express (backend) app (3000:5000 respectively). Both are running but when I setup a proxy in my frontend package.js, the frontend is still trying to grab localhost:3000 and is not using the proxy to request data from the backend. I noticed that my package-lock.js doesn't the proxy reference like my package.js does. Is package-lock.js not updating? Or is this another issue?
"name": "frontend",
"proxy": "http://127.0.0.1:5000",
"version": "0.1.0",
"private": true,
"dependencies": {..
I deleted the package-lock.json and regenerated it but no proxy mentioned in it again?

How to deploy React App client and Node Server to cPanel

I am trying to deploy a react app and a node server to my domain http://cv-devlabs.com/ with cPanel but failing to run. Most of the time I'm getting a "server responded with the 404 error".
I have tried methods from "hosting react app and express server cpanel" and "How to deploy a react app on cPanel?" and failed at both. I'm assuming I did something wrong here.
My file structure is:
Root-Folder--
-client
--build
--node_modules
--public
--package.json(client)(content added below)
-.gitignore
-package.json(server)(content added below)
-procfile
-server.js
Package.json (client)
"name": "client",
"homepage": "http://cv-devlabs.com/vidci-vid2/",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000",
Package.json(server)
{
"name": "vidci-vid",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"socket.io": "^2.3.0"
},
"scripts": {
"start": "PROD=true node server.js",
"postinstall": "cd ./client && yarn"
}
}
This is working fine on Heroku but on cPanel, it's not. The whole project can be found at https://github.com/ConsultVerraton/vidci-vid.git
Thanks to anyone who can help and thanks to anyone who can try. Do let me know if more information is needed.
Thanks
You cannot host a node.js app in most providers working with cpanel. If you want to host a node.js app you should deploy it on a vps. You can follow this tutorial for example:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
But in these cpanel providers, you could host a static react app (for example an app build with create-react-app). This kind of app does not need node.js at runtime. So you can build the assets and push them to your cpanel host.
You can follow this tutorial:
https://dev.to/crishanks/deploy-host-your-react-app-with-cpanel-in-under-5-minutes-4mf6
Yes you can, but it depend if the host provider allow it.
I'm actually running a express server on a cPanel account.
I didn't found the official documentation of cPanel but this is a pretty good one: How to create a Node.js application with cPanel using the Node.js Selector
If your looking to do it in command line, this the official documentation from cPanel :How to Install a Node.js Application.
I don't know about react but for anyone who wants to know how to deploy node js app to Cpanel this is a good source for him, this explains thoroughly how to deploy node js app to cpanel please check this

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!

Working Node.js modules into an application directory structure

I've begun using Node.js to make web applications. It's really awesome. I've come across a few modules that I want to incorporate into my build. I can work with the modules in Terminal after a global npm install. When it comes time to add them to my application, I have no idea how to go about placing them in my directory structure and I haven't found any good documentation on this. My typical node.js directory is:
ROOT
Server
server.js
node-modules
Client
index.html
css
-main.css
javascript
-main.js
-jquery.js
My process for installing the modules has been:
I cd into my Server file and run npm install
Then I go to my package.json file and include the module in the dependencies
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.1.0",
"jade": "*",
"stylus": "*",
"<node-module-here>": "1.0.x",
},
"engines": {
"node": "0.10.0",
"npm": "1.2.14"
},
}
After that, I head over to the server.js file I add:
module.exports = require('<path_to_node-module_lib>');
When I run functions that are dependent on the modules on the Client side (functions that work in Terminal), I don't receive an error but the function won't run. Because I'm not receiving errors I have no idea about how to debug. If anyone can recognize some fatal flaw in my structure or implementation and can offer some recommendations, I offer my first born.

Uploading Node.js app to cloudfoundry withour express error

Im trying to upload a node.js app into cloud foundry, im not going to use Express Framework, but when doing "vcm push" Im getting this error.
Uploading Application:
No such file or directory - /Users/jtomasrl/Code/node/pronto/node_modules/express
here is my package.json
{
"name": "karaoke-api",
"version": "0.0.1",
"dependencies": {
"pronto": "*",
"pronto-mongodb": "*"
},
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
}
}
Just for the sake of providing an "answer", when this situation does arise, it's worth emptying node_modules/.bin or even removing node_modules itself and re-installing modules with;
npm install

Resources