Input field validation in Node.js Express.js Mongoose - node.js

I'm new to Node.js I'm trying to transfer all I did before to this environment.
I'm using Express.js with Mongoose.
I come from a ASP.NET MVC environment where I'm used to define my model and then automatically scaffolding the form with personalized HTML.
I'd like to know if there's a way to scaffold form for edit insert and a way to go for input validation on single fields.
I've looked here http://plugins.mongoosejs.com but I didn't find what I needed.

If you are just starting the study Express, then play with express-validator with this micro tutorial
or use Mongo's build in validators

Related

How can I save client-side content-editable updates to mongodb database in node.js express app

What is the best way to persist user-generated data with NodeJS, Express, and MongoDB?
I'm building my first web-app using this stack (with bootstrap HTML/CSS and JS for the frontend) and I've realised that I need a data-binding solution. I'd rather avoid a complete rebuild of my front-end so it seems like React will be the best option, but I'd rather find out now if I'm missing something obvious.
The app will allow users to create 1-n documents, generate 1-n new components within them, and edit 1-n content-editable elements within those components.
I'm at the point where I've built the server, db, and frontend and the users and documents persist, but the components and their content does not.
The functionality I would like is that, when a user generates a new element or exits the contenteditable area of that element, any changes they have made will persist. I'd like to achieve this without a bazillion API calls.
Any assistance appreciated.
You may create page description in markdown and then render it to react components.
For example you can check https://www.gatsbyjs.org/ plus Remark Custopm blocks plugin - https://www.gatsbyjs.org/packages/gatsby-remark-custom-blocks/

What is the best practise of using same Model on several projects?

I create a ReactJS app using Sequelize and PostgreSQL database. I defined my models on my ReactJS API, but I need to use the same database (so the same models) on an other API.
How should I do so without writing again the definition of each model, because if I made a change, I would have to do it everywhere. Is there a better way to handle this king of problem?
Why I don't use the ReactJS API? Because when I built my React app, the API disappears: I'm using proxy.
var myModel = require('./models/myModel');
you can add by require here my model is in root directory inside model folder.
You could place the models in their own separate Node.js package, so they could be reused by both.
Please, refer to this: https://docs.npmjs.com/getting-started/creating-node-modules

The same code for client(Angular2) and server(nodejs)

Is there a way of using the same code for both Anglular2 models and mongoose models on express.js? The same question goes for Angular2 validation forms and express.js validation post requests(obviously one have to check the data twice on the client and on the server).
I moved from php to nodejs in hopes to avoid duplicate code. So how do I exactly do this?

Node form validations

I am new to node and building a simple book library app with express and mongodb. My forms work fine but I have having trouble with form validations. I initially used express validator but seems the code I wrote from the older version and it's legacy now. The problem is there are so many frameworks(Joi, express validator with joi, form input validator) and I am little confused now. One good thing with Java/Spring is that you don't have so many options. Can you please suggest what should be the best way to do that.
Thanks in advance.
There are two types of form validations client-side and server-side If you want to validate from server-side. You can use another node package to validate your form,
https://www.npmjs.com/package/form-validate
if you want to validate from client-side you can use jQuery plugin,
https://jqueryvalidation.org/

I'm using express js, mongoose, and ember js. Is there a way to write models only once?

I know Integrating Ember with Express JS says that you generally should have two representations of your models (one in backbone, one in express using mongoose schema), but I was wondering if there is some way to define a model once and have it translated into an ember model and a mongoose model on the fly.
I really don't want to repeat myself in code by writing the same model twice.
The only way that you can do this is by building a generator. I am currently looking into this using noeo4js as the back end, you can either read the ember model, and generate it based on its information or generate a ember model based on your backend's model, or generate both of a descriptor json object.

Resources