{"id":3974,"date":"2021-11-06T12:48:57","date_gmt":"2021-11-06T12:48:57","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=3974"},"modified":"2021-11-06T13:00:32","modified_gmt":"2021-11-06T13:00:32","slug":"cannot-find-module-express-with-node-js-using-docker","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/webdevel\/cannot-find-module-express-with-nodejs-using-docker\/5715.html","title":{"rendered":"Cannot Find Module &#8216;Express&#8217; With Node.Js Using Docker"},"content":{"rendered":"<p>I&#8217;m a newbie with Docker and I&#8217;m trying to start with NodeJS hosted in asphostportal.com so here is my question..<\/p>\n<p>I have this Dockerfile inside my project:<\/p>\n<p>FROM node:argon<\/p>\n<p># Create app directory<br \/>\nRUN mkdir -p \/home\/Documents\/node-app<br \/>\nWORKDIR \/home\/Documents\/node-app<\/p>\n<p># Install app dependencies<br \/>\nCOPY package.json \/home\/Documents\/node-app<br \/>\nRUN npm install<\/p>\n<p># Bundle app source<br \/>\nCOPY . \/home\/Documents\/node-app<\/p>\n<p>EXPOSE 8080<br \/>\nCMD [&#8220;npm&#8221;, &#8220;start&#8221;]<\/p>\n<p>&nbsp;<\/p>\n<p>When I run a container with<\/p>\n<p>docker run -d -p 49160:8080 node-container<\/p>\n<p>&nbsp;<\/p>\n<p>it works fine..<br \/>\nBut when I try to map my host project with the container directory (<\/p>\n<p>docker run -p 49160:8080 -v ~\/Documentos\/nodeApp:\/home\/Documents\/node-app node-cont<\/p>\n<p>&nbsp;<\/p>\n<p>) it doesn&#8217;t work.<br \/>\nThe error I get is:<\/p>\n<p>Code:<\/p>\n<p>Error: Cannot find module &#8216;express&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ve tried with other solutions from related questions but nothing seems to work for me (or I know.. I&#8217;m just too rookie with this)<br \/>\nThank you !!I&#8217;m a newbie with Docker and I&#8217;m trying to start with NodeJS hosted in asphostportal.com so here is my question..<\/p>\n<p>I have this Dockerfile inside my project:<\/p>\n<p>FROM node:argon<\/p>\n<p># Create app directory<br \/>\nRUN mkdir -p \/home\/Documents\/node-app<br \/>\nWORKDIR \/home\/Documents\/node-app<\/p>\n<p># Install app dependencies<br \/>\nCOPY package.json \/home\/Documents\/node-app<br \/>\nRUN npm install<\/p>\n<p># Bundle app source<br \/>\nCOPY . \/home\/Documents\/node-app<\/p>\n<p>EXPOSE 8080<br \/>\nCMD [&#8220;npm&#8221;, &#8220;start&#8221;]<\/p>\n<p>&nbsp;<\/p>\n<p>When I run a container with<\/p>\n<p>docker run -d -p 49160:8080 node-container<\/p>\n<p>&nbsp;<\/p>\n<p>it works fine..<br \/>\nBut when I try to map my host project with the container directory (<\/p>\n<p>docker run -p 49160:8080 -v ~\/Documentos\/nodeApp:\/home\/Documents\/node-app node-cont<\/p>\n<p>&nbsp;<\/p>\n<p>) it doesn&#8217;t work.<br \/>\nThe error I get is:<\/p>\n<p>Code:<\/p>\n<p>Error: Cannot find module &#8216;express&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ve tried with other solutions from related questions but nothing seems to work for me (or I know.. I&#8217;m just too rookie with this)<br \/>\nThank you !!I&#8217;m a newbie with Docker and I&#8217;m trying to start with NodeJS hosted in asphostportal.com so here is my question..<\/p>\n<p>I have this Dockerfile inside my project:<\/p>\n<p>FROM node:argon<\/p>\n<p># Create app directory<br \/>\nRUN mkdir -p \/home\/Documents\/node-app<br \/>\nWORKDIR \/home\/Documents\/node-app<\/p>\n<p># Install app dependencies<br \/>\nCOPY package.json \/home\/Documents\/node-app<br \/>\nRUN npm install<\/p>\n<p># Bundle app source<br \/>\nCOPY . \/home\/Documents\/node-app<\/p>\n<p>EXPOSE 8080<br \/>\nCMD [&#8220;npm&#8221;, &#8220;start&#8221;]<\/p>\n<p>&nbsp;<\/p>\n<p>When I run a container with<\/p>\n<p>docker run -d -p 49160:8080 node-container<\/p>\n<p>&nbsp;<\/p>\n<p>it works fine..<br \/>\nBut when I try to map my host project with the container directory (<\/p>\n<p>docker run -p 49160:8080 -v ~\/Documentos\/nodeApp:\/home\/Documents\/node-app node-cont<\/p>\n<p>&nbsp;<\/p>\n<p>) it doesn&#8217;t work.<br \/>\nThe error I get is:<\/p>\n<p>Code:<\/p>\n<p>Error: Cannot find module &#8216;express&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ve tried with other solutions from related questions but nothing seems to work for me (or I know.. I&#8217;m just too rookie with this)<br \/>\nThank you !!<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":4},"question-category":[57],"question_tags":[],"class_list":["post-3974","question","type-question","status-publish","hentry","question-category-webdevel"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/3974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=3974"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=3974"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=3974"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=3974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}