Archive | JS

RSS feed for this section

Node.js: how to fix error server error at Socket.onPacket

How to fix Node.js client connect_error: Main raison is mismatched versions of socket.io in client and server. You can choose the match JS client library at: https://cdnjs.com/libraries/socket.io or use /socket.io/socket.io.js on your server eg: https://ws.tutorialspots.com:31111/socket.io/socket.io.js

Read full story Comments { 0 }

Node.js: how to stream a mp4 file

How to stream a mp4 file with Node.js Run test Note: fs.statSync will throw an error if file not exists: So, you should use try catch clause to catch this error:

Read full story Comments { 0 }

JS: Calculate Distance Between Two Coordinates

This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations: Example: Result: 423232.8593012345 Note: Result as meters Ellipsoidal parameters: Name Major axis, a (km) Flattening (f) WGS84 6378.13700 1/298.257223563 GRS80/NAD83 6378.13700 1/298.257222101 WGS66 6378.145 1/298.25 GRS67/IAU68 6378.16000 1/298.2472 WGS72 6378.135 […]

Read full story Comments { 0 }

How to detect WebView Android and UIWebView IOS

Read first: Example User Agent Strings mobile How to detect WebView Android We see that, WebView user-agent string contains string Version, we do a test: Result: Other test: Result: So, we have method: How to detect UIWebView IOS Example: Result: Update:

Read full story Comments { 0 }

GMaps: how to open all infoWindow when loaded map

Simple you can do it with some simple line code: Example:

Read full story Comments { 0 }

Javascript: how to unshift an object?

How to unshift an object in Javascript? Here my method: Example: Result:

Read full story Comments { 0 }

Javascript: how to reverse an object?

How to reverse an object in Javascript ? Here my method: Example: Result:

Read full story Comments { 0 }

Date setTimezoneOffset method

As you all know, all date methods work only in the context of local time (user) or UTC, but sometimes you want to work in other contexts (time zones), the standard js forgot about the antagonist for getTimezoneOffset, and this is my method: Result:

Read full story Comments { 0 }

How to create websocket secure by using NodeJS

Method 1: In this article: How to run a https website with Nodejs, express and socket.io Method 2: use NGINX file .conf Now, you can use websocket to create websocket secure: Read more: Example chat application using Nodejs + Socket.io Example chat application using Nodejs + ws Example chat application using Nodejs + Websocket

Read full story Comments { 0 }

How to run a https website with Nodejs, express and socket.io

Step 1: generate RSA key Use command line: (on Windows we can use Cygwin) Result: Step 2: create file csr.pem Result: Step 3: create SSL certificate file Result: Note: this is in practice, in production you must buy one certificate or use free SSL Step 4: continue with Nodejs app here an example app: app.js […]

Read full story Comments { 1 }