Enabling HTTPS on express.js

In express.js (since version 3) you should use that syntax: var fs = require(‘fs’); var http = require(‘http’); var https = require(‘https’); var privateKey = fs.readFileSync(‘sslcert/server.key’, ‘utf8’); var certificate = fs.readFileSync(‘sslcert/server.crt’, ‘utf8’); var credentials = {key: privateKey, cert: certificate}; var express = require(‘express’); var app = express(); // your express configuration here var httpServer = … Read more

Express.js – app.listen vs server.listen

The second form (creating an HTTP server yourself, instead of having Express create one for you) is useful if you want to reuse the HTTP server, for example to run socket.io within the same HTTP server instance: var express = require(‘express’); var app = express(); var server = require(‘http’).createServer(app); var io = require(‘socket.io’).listen(server); … server.listen(1234); … Read more

Error message “error:0308010C:digital envelope routines::unsupported”

Here are two options now – 1. Try to uninstall Node.js version 17+ and reinstall Node.js version 16+ You can re install the current LTS Node.js version from their official site. Or more specific downloads from here; You can use NVM (Node Version Manager) Linux and Mac users can use this nvm package – https://github.com/nvm-sh/nvm … Read more

How do I run a node.js app as a background service?

Copying my own answer from How do I run a Node.js application as its own process? 2015 answer: nearly every Linux distro comes with systemd, which means forever, monit, PM2, etc are no longer necessary – your OS already handles these tasks. Make a myapp.service file (replacing ‘myapp’ with your app’s name, obviously): [Unit] Description=My … Read more

npm install vs. update – what’s the difference?

The difference between npm install and npm update handling of package versions specified in package.json: { “name”: “my-project”, “version”: “1.0”, // install update “dependencies”: { // —————— “already-installed-versionless-module”: “*”, // ignores “1.0” -> “1.1” “already-installed-semver-module”: “^1.4.3” // ignores “1.4.3” -> “1.5.2” “already-installed-versioned-module”: “3.4.1” // ignores ignores “not-yet-installed-versionless-module”: “*”, // installs installs “not-yet-installed-semver-module”: “^4.2.1” // installs … Read more

Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’

Change your file permissions… Like this First check who owns the directory ls -la /usr/local/lib/node_modules it is denying access because the node_module folder is owned by root drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules so this needs to be changed by changing root to your user but first run command below to check … Read more

How to get the full URL in Express?

The protocol is available as req.protocol. docs here Before express 3.0, the protocol you can assume to be http unless you see that req.get(‘X-Forwarded-Protocol’) is set and has the value https, in which case you know that’s your protocol The host comes from req.get(‘host’) as Gopal has indicated Hopefully you don’t need a non-standard port … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)