Is it fine to assign express js application instance to global scope?

310
April 10, 2017, at 11:32 AM

I am making my own node js structure and i am using express for http server. I also saw few other structures like loopback and sails.js They are also assigning some objects to global. So i am little bit confused about it that if i will make app global will it make any problem like security base performance base or any other issue with this way.

Before marking it negative please mention the reason in comment so that I will not repeat this mistake again

Thank you

Answer 1

In my opinion, having 1 or couple of variables in global context is fine. Root global objects should be very few. Anything required globally should be inside those objects.

Many libraries on client side bind to global object like moment, lodash, async (That is only way to make your object available to others,I guess)

Rent Charter Buses Company
READ ALSO
MySQL update trigger works but SELECT query does not see new data

MySQL update trigger works but SELECT query does not see new data

I have a MYSQL trigger that updates a table based upon the insert on another tableThe updates are working correctly and I can see them from MYSQL workbench

366
What is the difference between worker.kill vs process.exit in Node.JS

What is the difference between worker.kill vs process.exit in Node.JS

When using Nodejs's cluster feature, what is the difference between ending a forked process with process

312
FFmpeg stream dynamic png

FFmpeg stream dynamic png

I would like to know if its possible to stream a png or any kind of image using ffmpegI would like to generate the image contiously using nodejs that updates every 10 seconds

463
Setting up PayPal to run payments for Meteor app

Setting up PayPal to run payments for Meteor app

I have a question: How would I tokenize a credit card number in order to create necessary charges and subscriptions on the server in my Meteor app to be PCI compliant? I'm using Paypal's official paypal-node-sdk package

298