Muestra las diferencias entre dos versiones de la página.
| Próxima revisión | Revisión previa | ||
|
wiki2:nodejs:resources [2017/05/10 17:35] alfred creado |
wiki2:nodejs:resources [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 8: | Línea 8: | ||
| app.use(bodyParser.urlencoded({extended:false})); | app.use(bodyParser.urlencoded({extended:false})); | ||
| </code> | </code> | ||
| + | |||
| + | ===== Nodemon ===== | ||
| + | To mantain the server up: ''npm install nodemon -g''. Now the app.js and all its folder will be refreshed without needing to restart. | ||
| + | <code> | ||
| + | $ nodemon | ||
| + | </code> | ||
| + | |||
| + | ===== ejs ===== | ||
| + | ''npm install ejs --save'' \\ | ||
| + | Using files .ejs | ||
| + | <code> | ||
| + | res.render('index', { | ||
| + | title: 'Customers' | ||
| + | }); | ||
| + | ... | ||
| + | <h1><%= title %></h1> | ||
| + | </code> | ||
| + | ==== Partials ==== | ||
| + | Header | ||
| + | <code> | ||
| + | <html> | ||
| + | <header></header> | ||
| + | <body>... | ||
| + | </code> | ||
| + | Footer | ||
| + | <code> | ||
| + | </body></html> | ||
| + | </code> | ||
| + | Body | ||
| + | <code> | ||
| + | <% include partials/header %> | ||
| + | <h1>... | ||
| + | <% include partials/footer %> | ||
| + | </code> | ||
| + | ==== Iterations ==== | ||
| + | <code> | ||
| + | <ul> | ||
| + | <% users.forEach(function(uer){ %> | ||
| + | <li> <%= user.firstName %> </li> | ||
| + | <% }) %> | ||
| + | </ul> | ||
| + | </code> | ||
| + | |||
| + | ===== Express Validator ===== | ||
| + | ''npm install express-validator --save'' | ||
| + | <code> | ||
| + | var expressValidator = require('express-validator'); | ||
| + | </code> | ||
| + | You will find some examples in its webpage: https://github.com/ctavan/express-validator | ||
| + | <code> | ||
| + | req.checkBody('Email', 'Email is required).notEmpty(); | ||
| + | var errors = req.validationErrors(); | ||
| + | if (errors) { | ||
| + | |||
| + | } else { | ||
| + | // success | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | ===== MongoJS ===== | ||
| + | ''npm install mongojs --save'' | ||
| + | <code> | ||
| + | db.users.find(function (err, docs) { | ||
| + | res.render('index', { | ||
| + | title: 'Customers', | ||
| + | users: docs | ||
| + | }); | ||
| + | }); | ||
| + | </code> | ||
| + | |||
| + | ===== Config JS ===== | ||
| + | |||
| + | * https://www.npmjs.com/package/config-js | ||
| + | |||
| + | <code> | ||
| + | var Config = require('config-js'); | ||
| + | var path = require('path'); | ||
| + | |||
| + | var config = new Config(path.join(__dirname, '/config/config.js')); | ||
| + | |||
| + | var logOnOptions = { | ||
| + | 'accountName': config.get('steam.username'), | ||
| + | }; | ||
| + | </code> | ||
| + | |||
| + | <code> | ||
| + | exports.config_file_path = function () { | ||
| + | var path = require('path'); | ||
| + | var is = require('is2'); | ||
| + | |||
| + | var pathToConfigFile = path.join(__dirname, '/config/config#.js'); | ||
| + | var idx = pathToConfigFile.indexOf('#'); | ||
| + | var config_value = process.env.EBOT_CONFIG; | ||
| + | if (config_value != undefined) | ||
| + | config_value = '.' + config_value; | ||
| + | else | ||
| + | config_value = ''; | ||
| + | pathToConfigFile = pathToConfigFile.substr(0, idx) + config_value + pathToConfigFile.substr(idx+1); | ||
| + | console.log(pathToConfigFile); | ||
| + | return pathToConfigFile; | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | ===== Mongoose ===== | ||
| + | |||
| + | |||
| + | |||
| + | |||