Proper there is some form in the file.

<form action="/form" method="POST"> <input type="text" name="first_name" /> <input type="submit" value="Send" /> </form> 

It is processed in app.js

 app.post('/form', function(req, res, next){ код обработки формы, заносит данные в БД }); 

Everything works well for me. It is necessary to take out the processing code of the form from app.js to a separate file. If the form processing is 20, the app.js file will be huge in terms of the number of lines. Do not scold, I just learn node.js. Help me please.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You can make the module.

 module.exports.formHandler = function(req, res, next) { }; 

And in app.js do

 var handlers = require('module-name'); app.post('/form', handlers.formHandler); 
  • Thank you so much for your help. - Vasil Mikolajovich