Notify Spotify App with NodeJS server - node.js

I have a NodeJS server running on Heroku, and I want to send some data to my local Spotify app (which is not online since Spotify wont accept any new apps currently).
I tested this with a local NodeJS server as follows and it worked perfectly.
I send the arguments in my NodeJS server using:
open("spotify:app:app_name:some:arguments:here");
I catch the arguments in my local Spotify App using:
models.application.addEventListener('arguments', function() {
if (models.application.arguments[0] == "some") {
...
}
else if (models.application.arguments[1] == "arguments") {
...
}
});
However, now that I have my NodeJS server online, the arguments don't get passed anymore, I think because the open(..) function doesn't work properly anymore.
(Note: My NodeJS server is running fine, I think it's just the open(..) function that fails)
EDIT: I also tried this opener: https://github.com/domenic/opener but to no avail..
Any tips?

Related

How to configure node js application for deployement with mongo DB and vercel?

I finished an application with JS, Mongo Db Atlas, and node Js(express). It works fine locally on my computer.
I am trying to put it online with vercel. I have linked my vercel account to Github. The front end part of my application works fine but every request to the backend don't work...
This is the error message that i get :
Failed to load resource: net::ERR_CONNECTION_REFUSED.
Is there somethin that i am supposed modify in my code when I put it online ?
My request still look like this :
const fetchCardList = () => {
fetch("http://localhost:5000/api/card/")
.then((reponse) => reponse.json())
.then((allSpikemmon) => {.................
Am i supposed to replace localhost:5000 by something ?
Thanks a lot !

Trying to run Signalr client on the server side NodeJS

I have a 3rd party server that runs SignalR. In order to connect to that server and read messages i have created a javascript code that should run from NodeJS on ec2 (Linux) instance. The issue is that when i try running my code that only connects to the server i'm getting this error:
.....node_modules/signalr/jquery.signalR.js:1085
}(window.jQuery, window));
^
ReferenceError: window is not defined
What kind of window? I have an ssh-only linux server? My existing JS code is this:
const signalR = require("signalr"); //here i can't use #aspnet/signalr or #microsoft/signalr because those aren't compatible with SignalR that's on the 3rd party server. UGH Microsoft!
let connection = new signalR.HubConnectionBuilder().withUrl("https://myurl/signalr/hubName")
.configureLogging("warn")
.build();
connection.start().then(() => {
console.log("yeeey!");
}).catch((e) => {
console.log(e);
});
What are my options here in order to run this? I have installed NodeJS on ec2 instance using official Amazon tutorial so it should be the latest current version - 13.2
Found a solution.... This library solved my problems
Please write this:
import * as signalR from '#aspnet/signalr';

node.js error ECONNREFUSED on localhost url only

I have a node app, hosted on heroku, where I'm trying to hit an API that returns some JSON. That API I'm calling lives with the same app that I'm calling it from (e.g. The node app hosts my web app and has an API that generates JSON from my db).
I'm using the request npm module to make my API call. When deployed to heroku, when I use localhost:8080 as the url in the function I get the error below, but when I use the actual url where my app is hosted on heroku, it works fine. I have dev/staging/prod environments so I don't want to hard code the url.
Thing is, it works fine locally on my machine, so I'm not sure what the issue is - I'm assuming it has something to do with heroku since that's the only difference, but I'm not very familiar with this type of error.
Also - if it helps, I can hit both urls in the browser fine, locally, and on the heroku app.
request('http://localhost:8080/api/pictures', function (error, response, body) {
// this throws error: "connect ECONNREFUSED"
});
request('http://myapp.herokuapp.com/api/pictures', function (error, response, body) {
// this works
});
connect ECONNREFUSED: the two things you want to look at first:
Is the service you're trying to connect to enabled and started?
Is there are firewall between the client and the service host/service port?
In your case:
1) I assume you've started Heroku locally (on a Windows PC?)
2) I also assume it's running on port 8080 (per your notes)
3) Please check your local firewall software, to make sure Heroku and/or port 8080 are enabled. Do you have any antivirus programs (which might introduce their own firewalls)?
4) Also, please look at these links:
http://windows.microsoft.com/en-us/windows/communicate-through-windows-firewall#1TC=windows-7
http://windows.microsoft.com/en-us/windows/open-port-windows-firewall#1TC=windows-7
https://github.com/heroku/heroku/issues/1046
http://www.debian-administration.org/article/120/Application_level_firewalling

Websocket server running fine but cannot connect from client (what url should I use?)

OK this is very simple to anyone who's used websocket and nodejs.
I have created a websocket server named ws_server.js and put it in C:\Program Files (x86)\nodejs where I have installed the nodejs framework. I started the server and it is running and it says it's listening on port 8080. So far so good, I have the server running.
Now I simply want to connect to it from client code so that I can do all that lovely stuff about capturing events using event listeners etc. The problem is, embarassingly, I cannot figure out what URL to use to connect to my websocket server.
function init() {
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket("ws://localhost:8080/"); // WHAT URL SHOULD BE USED HERE?
websocket.onopen = function(evt) { alert("OPEN") };
websocket.onclose = function(evt) { alert("CLOSE") };
websocket.onmessage = function(evt) { alert("MESSAGE") };
websocket.onerror = function(evt) { alert("ERROR") };
}
function doSend(message) {
// this would be called by user pressing a button somewhere
websocket.send(message);
alert("SENT");
}
window.addEventListener("load", init, false);
When I use ws://localhost:8080 the only events that trigger are CLOSE and ERROR. I cannot get the client to connect. I must be missing something very simple. Do I need to set up my nodejs folder in IIS for example and then use that as the URL?
Just to reiterate, the websocket server is running fine, I just don't know what URL to use to connect to it from the client.
EDIT: The websocket server reports the following error.
Specified protocol was not requested by the client.
I think I have got it working by doing the following.
var websocket = new WebSocket("ws://localhost:8080/","echo-protocol");
The problem being that I needed to specify a protocol. At least now I get the onopen event. ...if nothing much else
I was seeing the same error, the entire web server goes down. Adding the protocol fixes it but leaves me wondering why it was implemented this way. I mean, one bad request should not bring down your server.
You definitely have to encase it a try/catch, but the example code provided here https://www.npmjs.com/package/websocket (2019-08-07) does not. This issue can be easily avoided.
I just wanted to share a crazy issue that I had. I was able to connect to a websocket of an old version of a 3rd party app in one computer, but not to a newer version of the app in another.
Moreever, even in new computer with the new version of the app, The app was able to connect to the websocket, but no matter what I did, when I tried to connect with my own code, I kept getting the error message that the websocket connection failed
Long story short, They changed an apache configuration that allowed connecting to the websocket via a proxy.
In the old version, apache config was:
ProxyPass /socket/ ws://localhost:33015/ retry=10
ProxyPass /socket ws://localhost:33015/ retry=10
In the new version, apache config was changed to:
ProxyPass /socket/ ws://localhost:33015/ retry=10
By bad luck, I was trying to connect to ws://localhost/socket and not to ws://localhost/socket/. As a result, proxy was not found, and connection returned an error.
Moral of the story: Make sure that you are trying to connect to a websocket url that exists.
For me, the solution was to change the URL from ws:// to wss://. This is because the server I was connecting to had updated its security, and now only accepted wss.

how to embed nodejs application on client website?

firstly sorry for not standard English. : D
I have a chat application using nodejs, expresss finished running on port 3000. So I want to embed in website application clients, then how?
I had to use ajax load, but can not be:
jQuery.ajax({
type:"GET",
url:"http://localhost:3000/client/",
success: function (data){
jQuery('body').append(data);
}
});
Since you are using socket.io at server side then you can get its reference at the client using below line (jquery required):
$.getScript(host+'socket.io/socket.io.js', function()
{
var clientSocket = io.connect(host);
// ... do other stuff with your socket
});
Where host is your server host name e.g. http://192.168.1.5:3000/ where your nodejs application is deployed.
For more information see here for more client - server communication exposed events.
try the example from http://book.mixu.net/node/ch3.html (it uses long-polling) once done with it use socket.io

Resources