Controller Reference Is Not Defined Node.js Application

I'm working on a node.js single-page web application where I wanna use MVC. On my back-end, i'm using postgres database to store data that will be provided by the user throught forms interaction. For this, i'm also using Sequelize.

When 'npm start' runs, the application verifies if the database already exists locally, if not, then it is created with its tables and relations, just as expected.

On my front-end, the application loads a file called index.html (where all forms will be located). In this file, I'm trying to use my controllers to call 'create' methods using Sequelize, but i can't exacly call those functions on html script tag.

The first errors i was getting was 'required is not defined' when I was trying to do things like 'var PropController = require('../controllers/PropriedadeController.js')'. After some research, just figured out that it has somethings to do with browser/client-side in JavaScript.

I'm now trying to deal with this using Browserify, but still can't find out how it fits in my case. I did some research, but couldn't find a similar situation.

Basically, my idea is to reference all my controllers in a script.js file, and then browserify this file, in order to use it in my html file in the script tag.

My controller file:

const models = require("../models")

exports.findCreate = obj => {
    return new Promise((resolve, reject) => {
            attributes: ["propt_nomeProdutor"],

            where: { propt_nomeProdutor: obj.propt_nomeProdutor },

            defaults: {
                propt_nomeProdutor: obj.propt_nomeProdutor
            .then(resp => {
            .catch(e => {

My script.js file:

const ProdController = require("./ProdutorController");
module.exports = ProdController

And in my index.html file, after running 'browserify script.js -o bundle.js', i'm calling this generated script. So now, Inside a script tag, i'm trying to:

`(html form here)
<script src="../controllers/bundle.js"></script>
    // ProdController.findCreate(obj) ...

After trying this, i'm getting an error 'ProdController is not defined'. I even tried to browserify my controller file and my script.js into the bundle.js file, but then i'm getting an error witch I couldn't solve either:

Uncaught Error: Cannot find module './dialects/postgres/data-types'

I would like to know if there is any solution for this. I'm afraid that it's not possible to do this using these dependencies all together. I did a similar application using Electron, but now i'm trying to deal with a browser, and can't figure out how to do it.

This project is in my github repo:

Any help will be greatly appreciated.



I think you are not familiar with front-end and back-end concepts. Controller is used at back-end side and it cannot use at front-end side. If you want to call a controller method you should write a new router to execute that method.

And another important thing is require method belongs to Node scripts and cannot be used at front-side.