task

node - expressjs

[previously]

  1. [REFERENCE]
    1. ] # 5218 - learning node on windows -
    2. ] # 191 - BOOK of javascript 
    3. ] # # - API 4.x 
    4. ] # # - stackoverflow-express 
    5. ] # # - ExpressJS How to structure an application? 
  2. ] NEW task IN
    1. ] why express - personally, i fell into using/learning express, was included in a starter site template, then in a tutorial i looked at, it seemed as good as any i had used before(i hadnt used any before), and 100K+ cant be wrong can they?
  3. ] example - my first "express" app
    1. ] PASS -
    2. ] using
    3. ] PRB with calling out to an api and processing the results
    4. ]
  4. [00:00] NEW task IN CREATE-article# #
    1. ] # # - overview - a lightweight server side (MVC) application development framework, popular,
      1. PROs =
      2. CONS =
      3. ALTS = sails.js, loopback.io
      4. ] express or sails - http://www.quora.com/Should-one-learn-Express-js-or-Sails-js sails = express + ORM + MVC structure, ALSO loopback.io
  5. [00:00] NEW task IN
    1. ]
  6. [00:00] how to - understanding how express works
    1. ] app.js - your web server, the 'main' or your app
      1. ] my example/sample program is named - server.js
      2. ] this is the name of the file to launch when you start your app
        1. ] node server.js
      3. ] it is the main configuration file for your Express app.
      4. ] .listen(port) -
    2. ] requires
      1. ] telling your app which program/packages and data to use The require function is pretty straight forward. It's a built-in Node function that imports an object (module.exports) from another file or module.
      2. ] /routes - specifing a file which will define which routes your app will use
      3. ] /users -
    3. ] requires --> module.exports()
      1. ] define code that will be avail, code file needs module.exports{ function(){} }, app need requires(''
    4. ] app.set
      1. ]
      2. ] app.set('views', path.join(__dirname, 'views'));  specify the path to the view folder
      3. ] app.set('view engine', 'jade');  - specify which view engine to use
      4. *] CC jade templating package -   simplifies your HTML files and gives you conditionals, Instead of saving your files as .html, you'll now have to save them as .jade in your /views folder
    5. ] app.use  
      1. ] tells the app how to use the parameters you're giving it. This can be a function or a path and a function
      2. ] Mounts the middleware function(s) at the path. If path is not specified, it defaults to “/”.
      3. ] example defaults - app.use(bodyparser.json())
    6. ] special 404
      1. ] not the result of an error but rather the app running out of {route} options.
      2. ] Once the request doesn't match any of the routes, it will reach the following function.
    7. ] error handling
      1. ] specify code in app.js to handle errors
      2. ] render full errors in development mode VS error messages in production
    8. ] module.exports
      1. ] Remember that require function?(#2) That makes use of the module.exports! When you want to use some variables or functions from another file, you attach them to the module.exports.
      2. ] example -
        1. var myModule = {
        2.   add: function (a,b){
        3.      return a+b;
        4.   }
        5. module.exports(myModule);
      3. ] add a requires statement to your app.js
        1. var myModule = require('./mymodule.js');
      4. ] use
        1. myModule.add(3,2); // 5
      5. ] CC - practical experience
        1. ] # 5273 -v-004-002 -   practical experience USING/implementing modules in the PASS app - SUMMARY = x] module works but diferent code than this document, ] unsuccessfull at making api call from within module, same code works in the 'index.js' page

[currently]

  1. ] adding requestjs
    1. ] for handling http requests

[next]

  1. ] http://expressjs.com/starter/basic-routing.html -
    1. ]
  2. ] http://jilles.me/getting-the-express-app-js/
    1. ]
  3. ] understanding express routes -
    1. ]
  4. ] http://eloquentjavascript.net/04_data.html - data structures objects and arrarys

 


 

2] understanding expressjs

 

// TRY adding special 404 - aka no routes matched
function next(err){
    alert('doodledoop');
}
 
app.use(function(req, res, next) {  
    var err = new Error('that piglet is NOT Found');
    err.status = 404;
    
   res.status(err.status || 500);
   res.render('./errors/404', {
        message: err.message,
        error: {}
        })
    //next(err);
  
});
Details Photos Edit more

Details

ID: 5257

NAME: CREATE-article-express

DESCRIPTION: 5257 - express - MVC framework for node

START DATE TIME: 2015-06-08 17:18:22

EST DURATION: 01:00:00

END DATE TIME: 2015-06-08 18:18:22

STATUS: To-Do

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

photos for this task

actions

Agenda Email task SMS task Priorities