call node js function from javascript
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost'); // connec to server
socket.on('news', function (data) { // listen to news event raised by the server
console.log(data);
socket.emit('my other event', { my: 'data' }); // raise an event on the server
});
</script>
var io = require('socket.io').listen(80); // initiate socket.io server
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' }); // Send data to client
// wait for the event raised by the client
socket.on('my other event', function (data) {
console.log(data);
});
});
Also in JavaScript:
- mongodb find all that dont have property
- front javascript read text file from remote
- how to compare elements in an array
- for function js
- javascript check if string contains character
- How to access the request body when POSTing using Node.js and Express
- trigger click on checkbox jquery
- javascript element by class
- how to make javascript function consise
- js set datetime
- create json string c#
- v-for vuejs
- nestjs AXIOS_INSTANCE_TOKEN
- === in js
- how to create duplicate key array in javascript
- Scroll to the top of the page using JavaScript?
- uuid react
- react html symbol code
- js use await in synchronous method
- express get cookie
- javascript null check
- counter with react hooks
- javascript loop through array backwords
- timezone in react js