index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const express = require('express');
  2. const path = require('path');
  3. const app = express();
  4. app.use(express.static('public'));
  5. app.get('/', (request, response) => {
  6. console.log(path.resolve(__dirname, 'index.html'));
  7. console.log(__dirname);
  8. response.sendFile(path.resolve(__dirname, 'index.html'));
  9. });
  10. app.get('/about', (request, response) => {
  11. response.sendFile(path.resolve(__dirname, 'about.html'));
  12. });
  13. app.get('/contato', (req, res) => {
  14. res.sendFile(path.resolve(__dirname, 'contato.html'));
  15. });
  16. app.listen(3000, () => {
  17. console.log('App listening on port 3000');
  18. });
  19. // const http = require('http')
  20. // const fs = require('fs')
  21. // ReadFile tem colocar a função depois que readFile é concluido, funão assincrona
  22. // const aboutPage = fs.readFile('about.html', (file) => {})
  23. // const aboutPage = fs.readFileSync('about.html');
  24. // const contatoPage = fs.readFileSync('contato.html');
  25. // const homePage = fs.readFileSync('index.html');
  26. // const server = http.createServer((request, response) => {
  27. // console.log(request.url);
  28. // if (request.url === '/about') {
  29. // return response.end(aboutPage);
  30. // } else if (request.url === '/contato') {
  31. // return response.end(contatoPage);
  32. // } else if (request.url === '/') {
  33. // return response.end(homePage);
  34. // } else {
  35. // response.writeHead(404);
  36. // response.end('The page not found');
  37. // }
  38. // });
  39. // server.listen(3000);