server.js 980 B

12345678910111213141516171819202122232425262728293031
  1. const app = require('../app');
  2. const db = require('../model/db');
  3. const createFolderIsExist = require('../helpers/create-directory');
  4. const PORT = process.env.PORT || 3000;
  5. const APP_NAME = process.env.APP_NAME;
  6. // const http = require('http');
  7. // setInterval(() => {
  8. // http
  9. // .get(`http://${APP_NAME}.herokuapp.com`, function (res) {
  10. // res.on('data', function (_chunk) {
  11. // console.log('HEROKU RESPONSE: PINGED EVERY 25 MINUTES');
  12. // });
  13. // })
  14. // .on('error', function (_err) {
  15. // console.log('HEROKU RESPONSE: NOT PINGED');
  16. // });
  17. // }, 25 * 60 * 1000);
  18. db.then(() => {
  19. app.listen(PORT, async () => {
  20. const DIR_UPLOAD = process.env.DIR_UPLOAD;
  21. const DIR_STATIC = process.env.DIR_STATIC;
  22. await createFolderIsExist(DIR_UPLOAD);
  23. await createFolderIsExist(DIR_STATIC);
  24. console.log(`Server running. Use our API on port: ${PORT}`);
  25. });
  26. }).catch((err) => {
  27. console.log(`Server not running. Error message: ${err.message}`);
  28. process.exit(1);
  29. });