On Apr 15, 2014, at 7:01 PM, Bartek Żółkiweski <[email protected]> wrote:
> Im starting to play with JavaSript, node.js, express-js. And my JavaScript
> skills are very low.
> Im trying to build simple app server - clients. So i decided to type some:
>
> appContext.js file where i wanna hold some contstant variables for server.
> For example application title, description etc...
>
> app.locals.title = 'my super app name';
> app.locals.description = 'super description';
> app.locals.port = 8081;
>
> I app.js there is "starting" part.
>
> var (...)
> express = require('express'),
> io = require('socket.io'),
> port = (process.env.PORT || 8081); // here i wanna use my
> appContext variable 'app.local.port' for example
> var hbs = require('express-hbs');
> var app = express();
> (...)
>
> The main question is how i can use include | require or w/e to execute
> appContext.js file inside app.js file? I tried to use require but it doesnt
> work. Insted require return me .. object or w/e it is. How i can use this
> object? Or maybe my thinking is wrong and i shouldnt use it in that way at
> all insted of ... exalcy - what should i use to store somewhere my
> constant/settings.
Simplest answer:
In appContext.js you could:
module.exports = app;
Or:
module.exports = app.locals;
Then in app.’s:
var appContext = require(‘appContext’);
…
…
port = process.env.PORT || appContext.locals.port;
Or:
port = process.env.PORT || appContext.port;
—ravi
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.