How do I install express package in

Following the article below, when I execute the last command

https://linode.com/docs/applications/containers/docker-container-communication/

$ docker exec -it node_container node home/app.js

I got an error says below.

I wonder how I can install express package into the container.
Do I need to do something on Dockerfile?

internal/modules/cjs/loader.js:583
throw err;
^

Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/app.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)

1 Reply

Hey there, since Express is a JavaScript package that is installed with Node Package Manager, my initial thought without thoroughly recreating this issue is that you should use NPM to install it into the package.json file for your Node.js app.

Try running this inside of your ~/app directory as your normal, non-root user with elevated privileges and let us know how it goes:

npm install express --save

After you've solidified these dependencies in your webapp, you will want to copy the Node.js npm dependency list from package.json to the Docker image.

For more info on how to accomplish this, please check out this section of Node.js' guide on this below:

Dockerizing a Node.js web app

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct