fork(2) download
  1. var express = require('express');
  2. var cookieParser = require('cookie-parser');
  3. var app = express();
  4. app.use(cookieParser());
  5. var products = {
  6. 1:{title:'삼성 겔럭시 S7'},
  7. 2:{title:'Apple iPhone 7'}
  8. };
  9.  
  10. app.get('/products', function(req, res){
  11. var output = '';
  12. for(var name in products){
  13. output += `
  14. <li>
  15. <a href="/cart/${name}">${products[name].title}</a>
  16. </li>`;
  17. }
  18. res.send(`
  19. <h1>쇼핑몰</h1>
  20. <ul>${output}</ul>
  21. <p><a href="/cart" title="카트에 추가하기">카트</a></p>`
  22. );
  23. });
  24.  
  25. app.get('/cart', function(req, res){
  26. var cart = req.cookies.cart
  27. if(!cart){
  28. res.send('카트가 없습니다!');
  29. }else{
  30. var output = '';
  31. for(var id in cart){
  32. output += `<li>${products[id].title} (${cart[id]})</li>`;
  33. }
  34. }
  35. res.send(`
  36. <h1>카트</h1>
  37. <ul>${output}</ul>
  38. <a href="/products">목록으로</a>`
  39. );
  40. });
  41.  
  42. app.get('/cart/:id', function(req, res){
  43. var id = req.params.id;
  44. if(req.cookies.cart){
  45. var cart = req.cookies.cart;
  46. }else{
  47. var cart = {};
  48. }
  49.  
  50. if(!cart[id]){
  51. cart = 0;
  52. }
  53. cart[id] = parseInt(cart[id])+1;
  54. res.cookie('cart', cart);
  55. res.send(cart);
  56. });
  57.  
  58. app.get('/count', function(req, res){
  59. if(req.cookies.count){
  60. var count = parseInt(req.cookies.count);
  61. }else{
  62. var count = 0;
  63. }
  64. count = count + 1;
  65. res.cookie('count', count);
  66. res.send('카운트 : '+count);
  67. });
  68.  
  69. app.listen(3306, function(){
  70. console.log('Conneted 3306 port!');
  71. });
Runtime error #stdin #stdout #stderr 0.12s 51080KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/home/e25EIX/prog.js:13
		output += `
		          ^
SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3