Node JS Socket.IO

//—————- HTTPS Server —————————————- var fs = require(‚fs‘); var https = require(‚https‘); var express = require(‚express‘); var app = express(); var options = { key: fs.readFileSync(‚/etc/letsencrypt/live/hg-system.com/privkey.pem‘), cert: fs.readFileSync(‚/etc/letsencrypt/live/hg-system.com/fullchain.pem‘) }; var server = https.createServer(options, app); var port = 3000; server.listen(port, function() { log(‚listening on *:‘ + port); }); app.use(express.static(‚public‘)); app.get(‚/‘, (req, res) => { res.sendFile(‚index.html‘); }); weiterlesen…

NodeJS DB Connection

//—————- SQL Server —————————————- var mysql = require(‚mysql‘); var db = mysql.createConnection({ host : ‚localhost‘, user : ‚dbuser‘, password : ‚dbpass‘, database: ‚dbname‘ }); db.connect(); db.query(‚SELECT 1 + 1 AS solution‚, function(err, rows, fields) { if (err) throw err; console.log(‚The solution is: ‚, rows[0].solution); }); process.on(‚exit‘, function (){ db.end(); console.log(‚Goodbye!‘); });

NodeJS HTTP/HTTPS – Server (with Let’s Encrypt SSL Cert)

Basic HTTP-Server var fs = require(‚fs‘); var http = require(‚http‘); var express = require(‚express‘); var app = express(); var server = http.createServer(app); var port = 3000; server.listen(port, function() { log(‚listening on *:‘ + port); }); app.use(express.static(‚public‘)); app.get(‚/‘, (req, res) => { res.sendFile(‚index.html‘); }); Extend your Server to HTTPS with Free SSL Cert var fs = weiterlesen…