0

I'm using appjs (with nodejs + chromium) in my desktop app. I need to include js files and call functions defined in those files in my app.js file (mainly in menu created using app.createMenu(..) ). So I tried to include the files using the below code given in http://appjs.org/, http://comments.gmane.org/gmane.comp.lang.javascript.nodejs/45736, but it's not working:

var appjs = require('appjs');

// serve static files from a directory
appjs.serveFilesFrom(__dirname + '/content');

Is there anything else need to be added to make this code working? Please help me.

Thanks in advance.

Sankar V
  • 4,110
  • 5
  • 28
  • 52

1 Answers1

0

.serveFilesFrom() does nothing more than serve static assets in the content directory. By static, this means CSS, HTML, and images as well as client-side JavaScript.

You still have to handle requests and dependency management on your own. This is simple enough to grasp, though.

A good way to go about it would be to start off developing your app using one of the existing starter package distributables, available on the AppJS homepage (make sure you choose the right one for your operating system), as it will have all the boilerplate code and configuration written for you.

razorbeard
  • 2,924
  • 1
  • 22
  • 29
  • Thanks for the answer. In my case the files didn't get included yet. I tried it by calling an on-click function defined in another js file. – Sankar V Feb 18 '13 at 10:13
  • AppJS exposes the `require` keyword to the global namespace on the client side as well as it's default implementation on the (in this case mock) server. If you want to reference something outside of it's containing file, you will have to assign it to `module.exports` first. – razorbeard Feb 18 '13 at 10:20
  • `var appjs = module.exports = require('appjs');` already tried this. I need to get all js files inside "content" folder (`appjs.serveFilesFrom(__dirname + '/content');`). – Sankar V Feb 18 '13 at 10:27
  • you should only assign something to `module.exports` if something else is going to use it. i.e do not assign `appjs` to `module.exports`. Assign what you want to make available to `appjs` to `module.exports`, then require it before you define `appjs`. – razorbeard Feb 18 '13 at 10:35