later on sponsored by
Ruby and Python
const http = require('http')
const server = http.createServer((request, response) => {
response.end('Hello World!')
})
server.listen(8000)
const net = require('net')
const sockets = []
const server = net.createServer((socket) => {
sockets.push(socket)
socket.on('data', data => {
for (const target of sockets) {
if (target === socket) continue
target.write(data)
}
})
socket.on('end', () => {
const index = sockets.indexOf(socket)
sockets.splice(index, 1)
})
})
server.listen(8000)
and notable success stories
Javascript is as old as the internet
and since it is a first class citizen in js world,
no need for additional serialization, mapping layers
doing more with less code and less hardware also means less time and less money which made everyone happy
It is very easy to deploy and run your code on any platform
npm founded soon after its take off and is the default standard for what it does ever since
Thanks to V8, it's quite efficient and performant
A huge community quickly gathered around it and new ways of doing everything with javascript started flourishing from everywhere
server.route({
method: 'GET',
path: '/hello',
handler: function (request, h) {
return'hello world';
}
});
// client side
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
// server side
io.on('connection', function(socket){
socket.on('chat message', function(msg){
console.log('message: ' + msg);
});
});
enforcing and maintaining code quality
ESLint has 250+ available rules
Desktop GUI framework. Node.js for backend and Chromium for front-end.
and Controversies
which means a single node process runs only on a single core and it can't make use of any additional cpu cores
However, fortunately there are workarounds like clustering or using process managers
if all you have is a hammer, everything looks like a nail
The pace for change of not only the ecosystem but also the platform might be challenging to keep up with
Both in language and project levels
really easy to mess up without type-safety,
requires more defensive coding, rigorous testing
packages, packages everywhere.
node_modules getting huge in size with no effort
module.exports = leftpad;
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
'sudo npm' was changing the ownership of system files, permanently breaking the operating system.
Ownership of a popular package gets compromised and injected malicious code steals npm credentials from running machines
Ignition
new interpereter
TurboFan
new optimizer
find me on github.com/koraytaylan