app.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * such as when you deploy to a server, or a PaaS like Heroku.
  9. *
  10. * For example:
  11. * => `node app.js`
  12. * => `npm start`
  13. * => `forever start app.js`
  14. * => `node debug app.js`
  15. *
  16. * The same command-line arguments and env vars are supported, e.g.:
  17. * `NODE_ENV=production node app.js --port=80 --verbose`
  18. *
  19. * For more information see:
  20. * https://sailsjs.com/anatomy/app.js
  21. */
  22. // Ensure we're in the project directory, so cwd-relative paths work as expected
  23. // no matter where we actually lift from.
  24. // > Note: This is not required in order to lift, but it is a convenient default.
  25. process.chdir(__dirname);
  26. // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files).
  27. var sails;
  28. var rc;
  29. try {
  30. sails = require('sails');
  31. rc = require('sails/accessible/rc');
  32. } catch (err) {
  33. console.error('Encountered an error when attempting to require(\'sails\'):');
  34. console.error(err.stack);
  35. console.error('--');
  36. console.error('To run an app using `node app.js`, you need to have Sails installed');
  37. console.error('locally (`./node_modules/sails`). To do that, just make sure you\'re');
  38. console.error('in the same directory as your app and run `npm install`.');
  39. console.error();
  40. console.error('If Sails is installed globally (i.e. `npm install -g sails`) you can');
  41. console.error('also run this app with `sails lift`. Running with `sails lift` will');
  42. console.error('not run this file (`app.js`), but it will do exactly the same thing.');
  43. console.error('(It even uses your app directory\'s local Sails install, if possible.)');
  44. return;
  45. }//-•
  46. // Start server
  47. sails.lift(rc('sails'));