How to fix “Error: The server does not support SSL connections” when trying to access database in localhost?

Here I provide a workaround for the question, and not the title of this post. A better answer to the post overall would probably address configuring SSL for the local machine. I arrived here trying to resolve the problem of finishing that Heroku tutorial mentioned in the question and setting up the Postgres database to … Read more

Cannot POST / error using express

This way you should try const port = 3000; var express = require(‘express’), app = express(); var bodyParser = require(‘body-parser’); app.use(express.static(__dirname + ‘/public’)); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.get(“https://stackoverflow.com/”, function(req, res){ res.render(‘form’);// if jade // You should use one of line depending on type of frontend you are with res.sendFile(__dirname + ‘/form.html’); //if html file … Read more

Deploy the backend and frontend on the same Heroku app/dyno

I just successfully completed this goal using static files created during a heroku postbuild step, as described in this blogpost. I have a React frontend (could be anything though) and Express API backend. Each process has its own port in dev, but deploying on Heroku uses just one total. Put the working frontend in a … Read more

How to config VSCode’s Organize Imports order?

The built-in “Organize Imports” functionality has no configuration, according to the documentation. You can customize import ordering using a third-party extension, such as alfnielsen.vsc-organize-imports or by using a separate linting tool like eslint or tslint. In eslint (my recommendation, since tslint has been deprecated), you’ll need to also use a plugin like eslint-plugin-import to get … Read more

Node.js – Mongoose – Check if a collection exists

Option 2 is probably the cleanest. Assuming you have a Mongoose Connection object named conn that’s been opened using mongoose.createConnection, you can access the native mongo Db object via conn.db. From there you can call collectionNames which should provide what you’re looking for: conn.db.collectionNames(function (err, names) { // names contains an array of objects that … Read more

What is the difference between “npm update -g”, “npm upgrade -g”, “npm install -g npm”, and “n stable”?

What those commands do: sudo npm update -g – this command updates all installed global packages to the the latest versions. sudo npm upgrade -g – it’s an alias for update command. sudo npm install -g npm – installs the latest available version of npm package. sudo npm cache clean -f && sudo npm install … Read more

List all public packages in the npm registry

http://blog.npmjs.org/post/157615772423/deprecating-the-all-registry-endpoint describes the deprecation of the http://registry.npmjs.org/-/all endpoint, and links to the tutorial at https://github.com/npm/registry/blob/master/docs/follower.md as an alternative approach. That tutorial describes how to set up a “follower” that receives all changes made to the NPM registry. That’s… a bit odd, honestly. Clearly such a follower is not an adequate substitute for getting a list … Read more

Best practice for nodejs deployment – Directly moving node_modules to server or run npm install command

Running npm install in production server cannot be done in certain scenario (lack of compiling tools, restricted internet access, etc…) and also if you have to deploy the same project on multiple machines, can be a waste of cpu, memory and bandwidth. You should run npm install –production on a machine with the same libraries … Read more