Herramientas de usuario

Herramientas del sitio


wiki2:nodejs:resources

¡Esta es una revisión vieja del documento!


NodeJS Resources

Body Parser

Con express:

var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));

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.

$ nodemon

ejs

npm install ejs –save
Using files .ejs

res.render('index', {
  title: 'Customers'
});
...
<h1><%= title %></h1>

Partials

Header

<html>
<header></header>
<body>...

Footer

</body></html>

Body

<% include partials/header %>
<h1>...
<% include partials/footer %>

Iterations

<ul>
<% users.forEach(function(uer){ %>
  <li> <%= user.firstName %> </li>
<% }) %>
</ul>

Express Validator

npm install express-validator –save

var expressValidator = require('express-validator');

You will find some examples in its webpage: https://github.com/ctavan/express-validator

req.checkBody('Email', 'Email is required).notEmpty();
var errors = req.validationErrors();
if (errors) {

} else {
  // success
}

MongoJS

npm install mongojs –save

db.users.find(function (err, docs) {
  res.render('index', {
    title: 'Customers',
    users: docs
  });
});

</code>

wiki2/nodejs/resources.1495104903.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)