Browser sync, gulp, mongodb and express server - express

Trying to put together a project running an express server and gulp, browsersync, nodemon and mongodb. However I seem to be an Error: listen EADDRINUSE when I add browsersync. Any idea how to do this?

This means you already have a program listening on the port you are trying to use. What port are you running your application on? Is it 3000? If so, stop all other programs you have running that are using that port and you'll be good to go.

Are you defining in the browser-sync configuration the port to use?
In that case, the port needs to be something different from the one (if any) defined from the proxy. This works in my setup:
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init(null, {
proxy: "http://localhost:3000",
browser: ['google chrome'],
port: 4000
});
});
As reference, the full gulpfile.js (that uses nodemon and browsersync) is here.

Related

How do I generate an SSL certificate for codeanywhere?

I want to have a server (webpack dev server) running in codeanywhere using https. How do I go about generating an SSL certificate so I can connect?
Chrome preferably however I will consider other browsers that could handle d3.js.
And the answer is: Run your service on port 3000. Codeanywhere will then auto configure a certificate for you.
To do this edit your webpack.config.js and ensure the following is in your dev server config:
devServer: {
host: '0.0.0.0',
port: 3000
}
If your container is running Apache you will need to stop it first (see http://www.learn4master.com/programming-language/shell/start-restart-and-stop-apache-on-linux the command depends on your host OS).

NPM local server port increments by 1

new to VueJS here. Normally, vue runs the project at localhost:8080
I noticed lately that the moment I'm restarting my local server running at localhost:8080 through npm run dev command, the default port just increased it's value by 1. (btw, i just had that screenshot few moments ago)
Is this some sort of an issue?
Maybe the port 8080 and 8081 are already in use. You should make sure that you shutdown the running instances of the server before starting a new one.

Webrtc doesn't work on host

I have an application that has video and sound communication.
I used Webrtc I created the connection like the following code
foundedPC.createOffer(function(desc) {
foundedPC.setLocalDescription(desc, function() {
console.log("Create offer" + callId);
hub.invoke("sendSignal", JSON.stringify({
"sdp": foundedPC.localDescription
}), callId);
});
}, function(error) {
console.log('Error creating session description: ' + error);
});
then I created the answer and return the answer packet
evrey thing works on the local system, I rent a stun server because I found the answer in this linkstack he said the problem is stun and turn server.
but it didn't work for me.
whenever I turn on my VPN and my client also turn on the VPN Webrtc work nicely.
I don't know how the vpn effect on webrtc connection
I am pretty sure the problem is still the lack of a TURN server. I would guess the configuration to access the rented STUN/TURN server was not right.
Maybe try something different, also a very cheap alternative, I use Digital Ocean and installed CoTurn as my STUN/TURN server on a Ubuntu droplet. You pay only $0.007 per hour for the droplet. If you don't use it anymore (I use it for testing at this moment) you just destroy the droplet and you don't pay anymore. If you make a snapshot of the droplet, you can easy reinstall the droplet when you want to use it again. Snapshots costs $0.05/GB/month.
Installing CoTurn on a Ubuntu machine is very easy:
Select Ubuntu 16.04.3 x64 or 17.10 x64 when creating a droplet.
Installing:
sudo apt-get update
sudo apt-get install coturn
Next, edit sudo vi /etc/turnserver.conf and change the following options:
fingerprint
lt-cred-mech
realm=ip-address-public-droplet
listening-ip=ip-address-public-droplet
user=test:test
Next, edit sudo vi /etc/default/coturn and add the following options:
TURNSERVER_ENABLED=1
Create or modify service package for our program:
sudo vi /etc/systemd/system/coturn.service
Then paste the content of this.
After modifying a unit file, you should reload the systemd process itself to pick up your changes:
sudo systemctl daemon-reload
Now the installation is complete, we'll start the Coturn daemon:
sudo systemctl start coturn
Since systemctl doesn't provide output, we'll check the status to verify that the service has started properly:
sudo systemctl status coturn
Now that we've manually started the daemon and verified that it’s running, we'll ensure that it restarts automatically at boot:
sudo systemctl enable coturn
In your app you need something like:
var pcConfig = {
'iceServers': [
{'urls': 'stun:ip-address-public-droplet:5349'},
{'urls': 'turn:ip-address-public-droplet:5349', 'username': 'test', 'credential': 'test'}
]
};
You can force your app using TURN by:
var pcConfig = {
iceTransportPolicy: "relay",
'iceServers': [
{'urls': 'stun:ip-address-public-droplet:5349'},
{'urls': 'turn:ip-address-public-droplet:5349', 'username': 'test', 'credential': 'test'}
]
};
When the connection is established you can check if TURN server (relay) is used by going through the stats page.
Chrome address bar: chrome://webrtc-internals or Firefox address bar: about:webrtc.
Look for the 'bold' header: Conn-audio-1-0 (googCandidatePair)
Use Nothing: googRemoteCandidateType: local
Use of STUN: googRemoteCandidateType: stun
Use of TURN: googRemoteCandidateType: relay
STUN might not be enough and you may need to use TURN as well.
Free servers are great, but they don't cut it for WebRTC - no one exposes his TURN server for others to use as that costs money (a more detailed explanation here).
You will need to install and run your own TURN server or use a third party service such as XirSys or Twilio NAT Traversal.

Accessing localhost outside of server

I am new to node.js and am trying to get into the hang of actually using it. I am very familiar with JavaScript so the language itself is self-explanatory but the use of Node.js is quite different from the browser implementation.
I have my own remote virtual server and have installed Node and the Package Manager and everything works as expected. I am not exactly a server extraordinaire and have limited experience with the Terminal and Apache Configurations.
I can run my server using:
nodejs index.js
Which gives me: listening on *:3300 as expected.
I can then access my localhost from the terminal using: curl http://localhost:3300/ which gives me the response I expect.
Given that the website that links to my server is https://example.com, how do I allow this link to access: http://localhost:3300/ so that I can actually use my node server in production? For example, http://localhost:3300/ runs a Socket Server that I would like to use using Socket.io on https://example.com/chat.html with the JavaScript:
var socket = io.connect('http://localhost:3300/', {transports: ['websocket'], upgrade: false});
Ok, this question has nothing to do with nodeJS.
localhost is a hostname that means this computer. it's equivalent to 127.0.0.1 or whatever IP address you can refer to your computer.
After the double colon (:) you enter the port number.
So if you want to make an HTTP call to a web-server running on your server, you have to know what is the IP address of your server, or the domain name, and then you call it with the port number where the server is running.
For Instance, you would call https://example.com:3300/chat.html to make an HTTP call to a server running on example.com with port 3300.
Keep in mind, that you have to make sure with your firewall configuration, that the specific port is open for incoming HTTP requests.

SailsJS on production - Error: listen EADDRINUSE

I have a VPS server with CentOS and Apache server.
But I want to run my node.js applications too. I am using sails.js
This sails application is trying to listen to port 80 of specified host.
Here is error (after sails lift running):
debug: Starting server in /var/www/user/data/nodeprojects/projectname...
info - socket.io started
debug: Restricting access to host: projectname.com
warn - error raised: Error: listen EADDRINUSE
warn:
warn: Server doesn't seem to be starting.
warn: Perhaps something else is already running on port 80 with hostname projectname.com?
What is the problem? Can I run both apache and nodejs servers on one server with one port (80)?
No, you cannot.
When a server process opens a TCP port to answer requests, it has exclusive use of that port. So, you cannot run both SailsJS and Apache servers on the same port.
Having said that, you can do lots of interesting things with Apache, such as proxying specific requests to other servers running on different ports.
A typical setup would have Apache on port 80 and SailsJS on port 8000 (or some other available port) where Apache would forward requests to certain URLs to SailsJS and then forward the reply from SailsJS back to the browser.
See either configuring Apache on Mountain Lion proxying to Node.js or http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache for example implementations of this approach.
you cannot use same port for different application. NodeJS can use any open port. What you need todo is port forwarding for your app. :)