uWebSockets.js/examples/HelloWorld.js

20 lines
578 B
JavaScript
Raw Normal View History

2018-10-28 15:07:21 +00:00
const uWS = require('../dist/uws.js');
const port = 3000;
2018-11-03 11:35:42 +00:00
const world = new (require('util').TextEncoder)().encode('World!');
2018-10-28 15:07:21 +00:00
uWS.App().get('/hello', (res, req) => {
2018-11-03 11:35:42 +00:00
res.end(world);
2018-10-28 15:07:21 +00:00
}).get('/*', (res, req) => {
res.writeHeader('content-type', 'text/html; charset= utf-8').end(req.getHeader('user-agent') + ' är din user agent, biatch!');
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
});
console.log('Timers will not work until us_loop_integrate is done');