0

I'm working on some server-side javascript and I have some data that I want to keep sensitive, so it's in a non-public facing directory. Let's say I put it inside a function - how do I then call that function from within another javascript file?

3
  • 1
    Why would your server side JavaScript be in a public facing directory in the first place? Commented Jun 10, 2013 at 11:10
  • 1
    The documentation for loading scripts from files in node.js can be found at nodejs.org/api/modules.html Commented Jun 10, 2013 at 11:10
  • Thanks very much - I've found out the answer from that documentation and have answered my post. Commented Jun 10, 2013 at 11:20

1 Answer 1

1

Thanks to Quentin for pointing me towards the relevant documentation. The solution I ended up with is:

sensitive.js:

exports.data = "data";

app.js:

var sensitive = require('./sensitive');
var data = sensitive.data;
Sign up to request clarification or add additional context in comments.

3 Comments

Don't add sensitive data to your codebase. Pull it in from the environment instead by putting the sensitive module in your home directory. nodejs.org/api/…
I'm using heroku to deploy this app, and am unsure of how to access the home directory. My deployment is just done by pushing the whole app directory to the heroku server. I'll look into it though, as others must have come across this problem.
On Heroku you can specify custom values using environment variables, then pick those up from a configuration module in your app. Usually sensitive data is in the form of crypto keys, passwords, etc so that's a reasonable place to put that from a logistical perspective.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.