Is it a good idea to modify server.js?

If I wanted to include code that should only run once, e.g. to open a database, is it a good idea to put that code in the server.js file in the root dir of a mojito app? If not, what are the alternatives?


  • BL
  • Oct 30, 2012
1 Reply
  • I would not put that or any other application code into the server.js file. If I want code to run only once, then I put it into a model or controller and use a place that is only executed during server startup. For example look at https://github.com/FabianFrank/trainingMojito/blob/master/lesson1/myWeatherApp/mojits/Weather/controller.server.js and you will see that everything after line 5 and before line 19 would only be executed once during startup.

Recent Posts

in Yahoo! Mojito