Search code examples
dockerdocker-composesails.jsdockerfilesails-mongo

ReferenceError in sailsjs application from docker container


I am working on sails application In my application I have used mysql and mongo adpater to connect with different database. Both db are hosted on somewhere on internet. Application is working fine in my local environment. I am facing issue once I add project to docker container. I am able to generate docker image and run docker container. When I call simple routers where DB connection is not exists it's working fine but when I call Testcontroller which is return data from mongodb. it give me ReferenceError: Test is not define. here Test is mongodb's entity.

DockerFile:

FROM node:latest
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "./"]
RUN npm install --verbose --force && mv node_modules ../
COPY . .
EXPOSE 80
CMD npm start

TestController

/**
 * TestController
 * @description :: Server-side actions for handling incoming requests.
 *
 * @help        :: See https://sailsjs.com/docs/concepts/actions
 */

module.exports = {
  index: async function(req, res) {
    var data = await Test.find(); // Here I am getting error Test is not define.
    res.json(data);
  }
};

Routes.js

'GET /test': {controller:'test', action:'index'}

Solution

  • I found issue I am moving node_modules to previous directory that is the issue.

    below Configuration works for me.

    FROM node:latest
    ENV NODE_ENV production
    WORKDIR /usr/src/app
    COPY ["package.json", "./"]
    RUN npm install --verbose --force
    COPY . .
    EXPOSE 80
    CMD npm start