Where Do I Store Application Variables

8 views
Skip to first unread message

pnewhook

unread,
Mar 18, 2010, 9:30:46 PM3/18/10
to nitro-devel
Hello,

Where would I enter variables like a connection string in a nitro app?
I'd like to have one place that I can store it and access anywhere in
the app. Is there an acceptable way to use a web.xml file and read
from it? Or would I it go in a jackconfig or narwhal.conf file? I've
had trouble figuring out which type of things should be tracked by
nitro vs. jack vs. narwhal

I've seen appenginejs apps using web.xml. How would I use it in Nitro?
I was looking at Apache Shiro for authentication and I was thinking
about how I would wire that in. Their docs give examples using the
web.xml.

Thanks

Dean Landolt

unread,
Mar 18, 2010, 10:36:09 PM3/18/10
to nitro...@googlegroups.com
Check out the "settings" module in http://github.com/kriszyp/commonjs-utils -- does a nice job of managing this for you (using a local.json file in your project) and you just require("settings").myConnectionString


--
You received this message because you are subscribed to the Google Groups "nitro-devel" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitro-devel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitro-devel?hl=en.


pnewhook

unread,
Mar 18, 2010, 11:58:20 PM3/18/10
to nitro-devel
Thanks. I gave that a shot. I tried putting a local.json file with
this content in the Nirto root folder (it does go in the nitro root,
correct? i.e.Downloads\narwhal\packages\nitro I also tried putting it
elsewhere in the file hierarchy but that didn't help.)

{"myConnectionString": "testString"}

then I modified the hello.js page from the example to this:

var myConnectionString = require("settings").myConnectionString;

exports.GET = function(env) {
return { body: [myConnectionString] };
}

but I keep getting this result on the page

TypeError: Cannot call method "toByteString" of undefined

I turned on debugging and I noticed that pkg[undefined] gets printed
out a lot in the USING and REQUIRED statements. For example:

REQUIRE: id[settings] baseId[C:/Users/Pete/Documents/Downloads/narwhal/
packages/nitro/example/src/root/hello] pkg[undefined]
basePkg[undefined]
USING: id[settings] pkg[undefined]
\\ settings
REQUIRE: id[packages] baseId[settings] pkg[undefined]
basePkg[undefined]
USING: id[packages] pkg[undefined]
\\\ packages
REQUIRE: id[./system] baseId[packages] pkg[undefined]
basePkg[undefined]
USING: id[system] pkg[undefined]


On Mar 18, 10:36 pm, Dean Landolt <d...@deanlandolt.com> wrote:
> Check out the "settings" module inhttp://github.com/kriszyp/commonjs-utils--does a nice job of managing


> this for you (using a local.json file in your
> project) and you just require("settings").myConnectionString
>
>
>
> On Thu, Mar 18, 2010 at 9:30 PM, pnewhook <peter.newh...@gmail.com> wrote:
> > Hello,
>
> > Where would I enter variables like a connection string in a nitro app?
> > I'd like to have one place that I can store it and access anywhere in
> > the app. Is there an acceptable way to use a web.xml file and read
> > from it? Or would I it go in a jackconfig or narwhal.conf file? I've
> > had trouble figuring out which type of things should be tracked by
> > nitro vs. jack vs. narwhal
>
> > I've seen appenginejs apps using web.xml. How would I use it in Nitro?
> > I was looking at Apache Shiro for authentication and I was thinking
> > about how I would wire that in. Their docs give examples using the
> > web.xml.
>
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nitro-devel" group.
> > To post to this group, send email to nitro...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > nitro-devel...@googlegroups.com<nitro-devel%2Bunsubscribe@googlegr oups.com>

George Moschovitis

unread,
Mar 19, 2010, 3:54:40 AM3/19/10
to nitro...@googlegroups.com
I typically use a config file in:

src/config.js

the config file exports configuration settings, for example:

exports.ADMIN_EMAIL = "ad...@example.com"
exports.API_KEY = "13213123123123123123213"

etc...

then  can use the config settings like this:

var CONFIG = require("config");
initAPI(CONFIG.API_KEY);

this works great in practice for me.

However, I am thinking about adding a Config middleware that just puts the CONFIG exports in env.config for easier access to the config variables.

-g.


--
You received this message because you are subscribed to the Google Groups "nitro-devel" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitro-devel...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nitro-devel?hl=en.

Christoph Dorn

unread,
Mar 20, 2010, 1:40:42 PM3/20/10
to nitro...@googlegroups.com
pnewhook wrote:
> I turned on debugging and I noticed that pkg[undefined] gets printed
> out a lot in the USING and REQUIRED statements. For example:

That is normal if you are not using using-packages in your program.

Christoph

Reply all
Reply to author
Forward
0 new messages