So I've been spending quite a bit of my spare time looking into node. It's actually more interesting than I first thought, Mainly because I can run it on my Raspberry Pi.
Currently I have a chat server running which uses socket.io. This was incredibly easy to set up a basic chat server (when I say basic, I mean basic..). I've been customising it visually and logically for a few days now.
Visually I have decided to make it look like a Linux terminal, this is done mainly with CSS but also with a JQuery plugin called Typed.js. I've used this before for other projects and I find it easy to use and it does what it says on the tin.
Logically I have enabled it to recognise URLs using regex, this was the easy part... I wrote the sendMessage functionality so the message sent would ignore HTML and JavaScript in order to stop injection attacks. This seems like a good idea at the time. Later on I introduced the regex to spot URLs in a string and apply the <a href> tag to them. when testing this i got the following:
Karl: This is a test <a href="http://www.google.co.uk">www.google.co.uk</a> end of test
So my way around this was to break up the message but keep the order, each URL found would be inserted as HTML, everything else inserted as text. I'm researching into how other chat clients resolve this issue, I think my way my have some security vulnerabilities, but hey, it's a good way to learn.
I'm also looking into file sharing and possibly enabling some kind of webcam chat. I'm currently looking at socket-signaler-client which I think has the ability to give me what I want.
Showing posts with label Node. Show all posts
Showing posts with label Node. Show all posts
Friday, 7 October 2016
Tuesday, 27 September 2016
Learning Node.js
Node.js has always looked interesting to me, yet I have never explored it properly.
Once I installed Node I realised I could just run the following in a console:
$ node
> console.log('Hello');
Hello
undefined
Undefined is returned because node returns the return value of each command. This command has no return value.
The reason people always mention web-servers is because its incredibly easy to create a basic web-server with node:
web-server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080);
console.log('Server running on port 8080.');
Every time I hear people mention Node.js its almost always followed by the words "web-server", so naturally I assumed Node.jswas a light weight web-server. Turns out (by just Googling node.js) that it is in fact just a JavaScript Run-time.
Once I installed Node I realised I could just run the following in a console:
$ node
> console.log('Hello');
Hello
undefined
Undefined is returned because node returns the return value of each command. This command has no return value.
The reason people always mention web-servers is because its incredibly easy to create a basic web-server with node:
web-server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080);
console.log('Server running on port 8080.');
Now running $ node web-server.js will launch the web-server, going to http://localhost:8080 will show the text.
Node.js has a very large number of library's which can be used to do almost anything. One project I am quite keen on is a drag and drop page which will parse a CSV file and output relevant data. I'm going to be working on this over the next few hours and I will update this post once complete.
Node.js has a very large number of library's which can be used to do almost anything. One project I am quite keen on is a drag and drop page which will parse a CSV file and output relevant data. I'm going to be working on this over the next few hours and I will update this post once complete.
Subscribe to:
Posts (Atom)