How do I fix npm’s global location?

npm uses a .npmrc file which should be in your home directory. (ie ~/.npmrc) In this file you should see a key value pair with the key being “prefix”. Try setting the value to something like “/usr/lib64”. So your .npmrc file would have the following in addition to whatever else you put in it: prefix … Read more

Changing Node.js listening port

There is no config file unless you create one yourself. However, the port is a parameter of the listen() function. For example, to listen on port 8124: var http = require(‘http’); http.createServer(function (req, res) { res.writeHead(200, {‘Content-Type’: ‘text/plain’}); res.end(‘Hello World\n’); }).listen(8124, “127.0.0.1”); console.log(‘Server running at http://127.0.0.1:8124/’); If you’re having problems finding a port that’s open, … Read more

Node.js – Zip/Unzip a folder

I’ve finally got it, with the help of @generalhenry (see comments on the question) and as mentioned in the comments, we need to compress the folder in two steps: Convert the folder into a .tar file Compress the .tar file In order to perform the first step, I needed two node.js modules: npm install tar … Read more

How to mount express.js sub-apps?

app.use(uri, instanceOfExpressServer) Just make sure you don’t call .listen on it. The alternative is to use require(“cluster”) and invoke all your apps in a single master so that they share the same port. Then just get the routing to “just work”

Sails.js + Passport.js authentication through websockets

Alternatively, you can hijack the ‘router:request’ event to plug in passport for socket requests. I do this in ‘config/bootstrap.js’: module.exports.bootstrap = function (cb) { var passport = require(‘passport’), initialize = passport.initialize(), session = passport.session(), http = require(‘http’), methods = [‘login’, ‘logIn’, ‘logout’, ‘logOut’, ‘isAuthenticated’, ‘isUnauthenticated’]; sails.removeAllListeners(‘router:request’); sails.on(‘router:request’, function(req, res) { initialize(req, res, function () { … Read more

How to stub a private method of a class written in typescript using sinon

The problem is that the definition for sinon uses the following definition for the stub function : interface SinonStubStatic { <T>(obj: T, method: keyof T): SinonStub; } This means that the second parameter must be the name of a member (a public one) of the T type. This is probably a good restriction generally, but … Read more