app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * app.js
  3. *
  4. * Use `app.js` to run your app without `sails lift`.
  5. * To start the server, run: `node app.js`.
  6. *
  7. * This is handy in situations where the sails CLI is not relevant or useful.
  8. *
  9. * For example:
  10. * => `node app.js`
  11. * => `forever start app.js`
  12. * => `node debug app.js`
  13. * => `modulus deploy`
  14. * => `heroku scale`
  15. *
  16. *
  17. * The same command-line arguments are supported, e.g.:
  18. * `node app.js --silent --port=80 --prod`
  19. */
  20. // Ensure we're in the project directory, so relative paths work as expected
  21. // no matter where we actually lift from.
  22. process.chdir(__dirname);
  23. // Ensure a "sails" can be located:
  24. (function() {
  25. var sails;
  26. try {
  27. sails = require('sails');
  28. } catch (e) {
  29. console.error('To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.');
  30. console.error('To do that, run `npm install sails`');
  31. console.error('');
  32. console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.');
  33. console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,');
  34. console.error('but if it doesn\'t, the app will run with the global sails instead!');
  35. return;
  36. }
  37. // Try to get `rc` dependency
  38. var rc;
  39. try {
  40. rc = require('rc');
  41. } catch (e0) {
  42. try {
  43. rc = require('sails/node_modules/rc');
  44. } catch (e1) {
  45. console.error('Could not find dependency: `rc`.');
  46. console.error('Your `.sailsrc` file(s) will be ignored.');
  47. console.error('To resolve this, run:');
  48. console.error('npm install rc --save');
  49. rc = function () { return {}; };
  50. }
  51. }
  52. // Start server
  53. sails.lift(rc('sails'));
  54. })();