Load “Vanilla” Javascript Libraries into Node.js

There are some third party Javascript libraries that have some functionality I would like to use in a Node.js server. (Specifically I want to use a QuadTree javascript library that I found.) But these libraries are just straightforward .js files and not “Node.js libraries”. As such, these libraries don’t follow the exports.var_name syntax that Node.js […]

SyntaxError: Use of const in strict mode

I’m working with node.js, and in one of my js files I’m using const in “strict mode”. When trying to run it, I’m getting an error: SyntaxError: Use of const in strict mode. What is the best practice to do this? Edit: ‘use strict’ const MAX_IMAGE_SIZE = 1024*1024; // 1 MB

Best approach to real time http streaming to HTML5 video client

I’m really stuck trying to understand the best way to stream real time output of ffmpeg to a HTML5 client using node.js, as there are a number of variables at play and I don’t have a lot of experience in this space, having spent many hours trying different combinations. My use case is: 1) IP […]

Should I check in node_modules to git when creating a node.js app on Heroku?

I followed the basic getting started instructions for node.js on Heroku here: https://devcenter.heroku.com/categories/nodejs These instruction don’t tell you to create a .gitignore node_modules, and therefore imply that node_modules should be checked in to git. When I include node_modules in git my getting started application ran correctly. When I followed the more advanced example at: https://devcenter.heroku.com/articles/realtime-polyglot-app-node-ruby-mongodb-socketio […]

XMLHttpRequest cannot load https://www.[website].com/

I have a Grunt process which initiates an instance of express.js server. This was working absolutely fine up until just now when it started serving a blank page with the following appearing in the error log in the developer’s console in Chrome (latest version): XMLHttpRequest cannot load https://www.[website].com/ No ‘Access-Control-Allow-Origin’ header is present on the […]

Get the _id of inserted document in Mongo database in NodeJS

I use NodeJS to insert documents in MongoDB. Using collection.insert I can insert a document into database like in this code: // … collection.insert(objectToInsert, function(err){ if (err) return; // Object inserted successfully. var objectId; // = ??? }); // … How can I get the _id of inserted object? Is there any way to get […]

What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

This documentation answers my question very poorly. I didn’t understand those explanations. Can someone say in simpler words? Maybe with examples if it’s hard to choose simple words? EDIT also added peerDependencies, which is closely related and might cause confusion.

JWT (JSON Web Token) automatic prolongation of expiration

I would like to implement JWT-based authentication to our new REST API. But since the expiration is set in the token, is it possible to automatically prolong it? I don’t want users to need to sign in after every X minutes if they were actively using the application in that period. That would be a […]

Viable options for running NodeJS on Android (Aug 2017)

There are a bunch of old SO threads dealing with running NodeJS on Android. Most of these are no longer viable (JXCore) and/or provide confusing, outdated, incomplete, or erroneous information. Therefore I have investigated what seems to be currently (as of August 2017) viable approaches and found three likely candidates. To decide between them I […]

How to deal with cyclic dependencies in Node.js

I’ve been working with nodejs lately and still getting to grips with the module system so apologies if this is an obvious question. I want code roughly like the following below: a.js (the main file run with node) var ClassB = require(“./b”); var ClassA = function() { this.thing = new ClassB(); this.property = 5; } […]

Node.js is the Best Javascript runtime in the world.