Render.com problem when deploying my Node.js application - javascript

currently I'm deploying a full stack Node.js application to Render.com. It seems like Render is not connecting to MySQL database. In vsCode, everything works fine but after deploying my application, database is not working and users cannot register or login to system. (I'm using MySQL workbench, not Xampp by the way)
Error is
Error: connect ECONNREFUSED 127.0.0.1:3306
Feb 7 06:52:58 PM at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
Feb 7 06:52:58 PM errno: -111,
Feb 7 06:52:58 PM code: 'ECONNREFUSED',
Feb 7 06:52:58 PM syscall: 'connect',
Feb 7 06:52:58 PM address: '127.0.0.1',
Feb 7 06:52:58 PM port: 3306,
Feb 7 06:52:58 PM fatal: true
Feb 7 06:52:58 PM }
My application uses port 3307, MySQL uses port 3306, why am i getting this error ? What should i do handle this error? A user can register and login the system in localhost but cannot login after deploying Render. This is because the application works in locahost ? This is my first time deploying a project. Thanks for your help
Edit: Front-end part can deploy but I think there is problem in database connection. I have no idea.

Related

Can't open text file when running a javascript file as a systemd service

I'm running a javascript file from node on my raspberry pi on startup automatically by using systemd service.
I loosely followed this guide to do the above.
When I run my javascript file manually using the command: Node Cloversale.js
it runs fine, and reads from my files as expected.
However, when running it as a service I get the following errors:
Feb 12 17:48:19 sensohub systemd[1]: Started Clover Service.
Feb 12 17:48:24 sensohub node[8640]: 2018-02-12 17:48:24.028 INFO ENOENT: no such file or directory, open 'token.txt'
Feb 12 17:48:24 sensohub node[8640]: Error: ENOENT: no such file or directory, open 'token.txt'
Feb 12 17:48:24 sensohub node[8640]: at Error (native)
Feb 12 17:48:24 sensohub node[8640]: 2018-02-12 17:48:24.068 INFO ENOENT: no such file or directory, open 'endpoint.txt'
Feb 12 17:48:24 sensohub node[8640]: Error: ENOENT: no such file or directory, open 'endpoint.txt'
Feb 12 17:48:24 sensohub node[8640]: at Error (native)
Feb 12 17:48:24 sensohub node[8640]: 2018-02-12 17:48:24.117 INFO Connected to OCR-Pi Server
I tried using chmod 644 on my services file, so I don't think its a permissions issue, but thats what other sites I've read seem to indicate.
Here is my clover.services file:
[Unit]
Description=Clover Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/node /home/pi/OCR-Pi/NSR/cloversale.js
[Install]
WantedBy=multi-user.target
Right after posting this I figured it out... Apparently I had to give read and write permissions to both the Javascript file and the .service file.
so typing chmod 644 cloversale.js fixed the issue.

Error when launching server.js on Ethereum Hello World app

I followed this tutorial with the web3 1.0 source code.
The tutorial suggested to use web3 0.20.x but web3 0.20.x could not be installed in my computer(Ubuntu 16.04.3).
https://medium.com/#mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2
https://github.com/mjhm/hello_world_dapp
I installed and downloaded necessary files and ganache-cli is launched successfully.
Listening on localhost:8545
eth_accounts
eth_gasPrice
eth_sendTransaction
Transaction: 0xffcd7597522313760d262b251037024002054f66fa354892fe65955510f0049c
Contract created: 0x91885fa1a0644951b43ddb57d8d50c441fee26c6
Gas usage: 354524
Block Number: 1
Block Time: Tue Dec 26 2017 06:23:23 GMT+0000 (UTC)
eth_getTransactionReceipt
eth_getCode
Now I want to launch http_server with npm run http_server command but I got error:
> hello_world_voting#1.0.0 http_server /home/g-iot-info/hello_world_voting
> ./server.js
Unhandled rejection Error: Provider not set or invalid
How do I solve this problem?
I don't know where I should look at first.
Thanks in advance.

Nodejs HTTP Request ERRCONNREFUSED

I am trying to start building node apps and having trouble with my instance.
After working with require('http').get(...) for some time and having no success, I decided to try the example from the API docs as follows.
var http=require('http')
http.get("http://www.google.com/index.html", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
http.get api, Nodejs.org
and for every single time that I have tried I receive an error saying ECONNREFUSED
More detailed error object below;
Got error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
`
I really don't know why this is and I get the same error message for every single host I try, even localhost/127.0.0.1, www.google.com, www.example.com
uname -a
Linux localhost 3.10.18 #1 SMP Fri Mar 20 20:43:59 PDT 2015 x86_64 x86_64 x86_64 GNU/Linux
node -v
v0.6.12
npm -v
1.1.4
After updating my Node to a more recent version I can use require('http').get(...) successfully.

'500' error with sails.js 'testProject'

Went to http://sailsjs.org/#!getStarted and went through the steps the page requires. In my Win7 environment, I have node running and tested. I installed sails.js, changed directories, and 'sails lift'. Sails.js succeeds in launching and the CLI looks like:
$ sails lift
info:
info:
info: Sails.js <|
info: v0.9.7 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
info: Server lifted in `c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails Project\t
estProject`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.
debug: --------------------------------------------------------
debug: :: Wed Nov 06 2013 14:06:25 GMT-0500 (Eastern Standard Time)
debug:
debug: Environment : development
debug: Port : 1337
debug: --------------------------------------------------------
But when I visit the port I get this on the page:
{
"status": 500,
"errors": [
"Failed to lookup view \"home/index\""
]
}
There is a very long trace at the CLI that begins:
error: Error rendering view at :: c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails
Project\testProject/views/home/index
error: Using layout located at :: c:\Users\Dad\My Documents\Aptana Studio 3 Workspace\First Sails
Project\testProject/views/layout
error: Server Error (500)
error: Error: Failed to lookup view "home/index"
at Function.app.render (c:\Users\Dad\AppData\Roaming\npm\node_modules\sails\node_modules\expr
ess\lib\application.js:495:17)
.
.
.
The global install of sails.js went fine. All files are present in the views directory. I'm running node v0.8.18 and other apps I have run/render fine. Looking at the '500.js' file in the 'config' directory, if the 'view doesn't exist, just send json' (which is what seems to be happening). But the view does appear to exist so ... what am I missing?
this is a known issue on windows. check the work around in the linked issue or use sails 0.9.4 till the next release.

cannot connect to TCP server on CloudFoundry (localhost node.js works fine)

I have trouble connecting to my TCP server example running on CloudFoundry. When running my app.js file on a local node.js installation, it works just fine. Specifically, when I run the CloudFoundry by using vmc push, the service starts and does not crash. Some IP connects to it, disconnects and as far as I can tell, the service keeps running.
I just cannot connect to it using using neither "telnet" nor "nc" (note both of these work fine when directed towards the localhost node.js server.
This fails:
> nc themagicsandbox2.cloudfoundry.com 8124
This works
> nc localhost 8124
hello from TCP server! (intended reply)
My code is submitted here and the Cloud Foundry stdout.log is submitted below it.
Code:
myTrace('loaded'); // myTrace prepends timestamp to text and sends to console.log
var tcpServer = require('net').createServer(function(sock) { //'connection' listener
sock.on('connect', function() {
myTrace('client ' + sock.remoteAddress + ':' + sock.remotePort +' connected');
sock.write('hello from TCP server!\r\n');
sock.pipe(sock);
});
sock.on('end', function() {
myTrace('client disconnected');
});
});
tcpServer.listen(8124, process.env.VCAP_APP_HOST || "localhost");
tcpServer.on('listening', function() {
myTrace('server is listening - bound!');
});
tcpServer.on('error', function(err) {
myTrace('server err: ' + err);
if (err.code == 'EADDRINUSE') {
myTrace('Address in use, retrying ...');
setTimeout(function() {
tcpServer.close(function (err) {
myTrace('server.close: ' + err);
});
tcpServer.listen(SLIDEIN_TCP_PORT, process.env.VCAP_APP_HOST || "localhost");
}, 1000);
}
});
tcpServer.on('close',
function() {
myTrace('server has closed');
});
stdout.log (CloudFoundry):
Getting file contents... OK
Fri Mar 15 2013 11:59:02 GMT+0000 (UTC) loaded
Fri Mar 15 2013 11:59:02 GMT+0000 (UTC) server is listening - bound!
Fri Mar 15 2013 11:59:03 GMT+0000 (UTC) client 172.30.50.10:31840 connected
Fri Mar 15 2013 11:59:03 GMT+0000 (UTC) client disconnected
stdout (localhost node.js):
Fri Mar 15 2013 12:57:39 GMT+0100 (CET) loaded
Fri Mar 15 2013 12:57:39 GMT+0100 (CET) server is listening - bound!
Fri Mar 15 2013 12:57:53 GMT+0100 (CET) client 127.0.0.1:52260 connected
Fri Mar 15 2013 12:57:59 GMT+0100 (CET) client disconnected
Fri Mar 15 2013 12:58:00 GMT+0100 (CET) client 127.0.0.1:52261 connected
Fri Mar 15 2013 12:58:01 GMT+0100 (CET) client disconnected
That's because requests are routed to your application using the host header, neither of which netcat or telnet send. When making the request with either of those you will probably get a 504 back from the router.
I think the problem is that there is a proxy or HTTP redirector between your TCP client and the cloudFoundry application.
Dan Highman's answer, that the redirection is controlled by the HOST 'header' is predicated on the fact that the redirector assumes that your client is using the HTTP protocol and has a 'host' header record to allow it to figure out which cloudFoundry app you want to talk to.
I think you are asking how to get a non-HTTP TCP connection to the application. I haven't figured that out either. The VCAP_APP_HOST environment var gives a private IP address (ie in the private 10.0.0.0 subnet) so that wasn't useful for getting from the public internet to the cloud host. (It may be useful for communication between apps served by the same network of cloud hosts.)
I tried to get around the problem by using UDP which is unidirectional and that covers the need of this server, it could make do with a receive only protocol for receiving data.
However, UDP is never going to work on CloudFoundry.com, because the ports aren't opened.
See the comment thread here:
Only the HTTP and HTTPS ports are open for an app to use on Cloud Foundry
So it seems that I am back to sending data to this server over HTTP after all, getting rid of the HTTP handshaking was the fundamental reason for writing this TCP server in the first place.

Categories

Resources