Wednesday, 8 March 2017

NodeJS noob. Access outer object inside a callback?

Hi, I'm new to Node.js. Looks very interesting but very messy to me in the beginning.I am using Express to do some web development tests, and I do not understand how I can access a module that I have required at the top of the script inside of a callback.In particular:const some_module = require('somemodule'); const app = express(); app.get('/', (req, res) => { // I would like to be able to use some_module here res.status(200).send('Hello, world!'); }); For example, some module is a logging module that allows me to write custom logs. I have no idea about how to solve this and I am seeking for help.Is this a proper request? If not, what is the proper manner? How do experienced NodeJS programmers do?Thank you very much

Submitted March 08, 2017 at 02:42PM by IaintBatman

No comments:

Post a Comment