Exploring the use of Node.js exclusive modules in Docker containers

I have a nodejs project that includes references to a module I developed and hosted in a private Github repository. The dependencies listed in the package.json file are as follows:

"dependencies": {
    ... other stuff ...
    "my_module": "git+https://github.com/me/mymodule.git",
}

While this setup works, I am looking to create a Docker container for my application without including git inside it. I am aware that I can host modules through private npm repositories, but I am searching for a method to have the build process retrieve the source code (including the referenced module) and then transfer it to the container.

I am willing to perform an npm install within the container, but having a git dependency would cause issues. Similarly, I do not want to run npm install on the build machine because I want the flexibility to select any container without risking the inclusion of unnecessary binaries from different operating systems.

One approach I thought about was relocating the "my_module" dependency to devDependencies, subsequently running "npm install --production" inside the Docker container, followed by manually transferring the specific module. However, such a solution contradicts the intended purpose of devDependencies.

Are there any better or recommended solutions available? I am open to exploring alternatives to hosting the module on Github if a more suitable option exists (though I utilize it on several projects specifically for this client).

Answer №1

If you're looking for a simple solution, here's one: Start by building the node application.

Execute the command npm install and so on.

Next, in your dockerfile, make sure to add the COPY command. This will specify the directory where the node project is installed and where you want it to be copied to.

Edit:

To resolve the concern raised by @angelok, remember to use npm rebuild once the project has been transferred into the docker image. This ensures that it is built with the correct dependencies based on the OS of the Docker image rather than the OS where the node packages were originally installed. Refer to the rebuild documentation here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Difficulty Loading Static JavaScript File in Express.js

Currently in the process of setting up an express server with create-react-app. Encountering this error in the console: Uncaught SyntaxError: Unexpected token < bundle.js:1 Upon clicking the error, it directs me to the homepage htm ...

What could be causing the rejection of my authorized XML signature?

My goal is to construct a signed XML post request where the XML content needs to be included in the body of the request. The signing process must adhere to the following specifications: The digest should utilize the inclusive canonicalization algorithm Th ...

Restrict users to submitting only one review per journal in Mongoose platform

I am currently working with three schemas: const journalSchema = new mongoose.Schema({ title: String, category: String, subcategory: String, review: [{type: mongoose.Schema.Types.ObjectId, ref: 'Review'}], link: String, description: S ...

Ways to address security flaws in Seriate and Lodash

One of the packages I'm using for my project is Seriate. To install, use 'npm install seriate'. After running this command, I encountered the following result: Discovered 17 vulnerabilities (9 low, 1 moderate, 7 high). I tried running ...

Running code in NodeJS with Express when a page is loaded

My goal was to verify the URL against an array and redirect it to an error page if necessary. I'm uncertain about how to execute code upon page load. I've searched extensively for a solution, but haven't found one yet. ...

What is the best way to identify a specific pattern within a string using regular expressions in JavaScript?

Looking for a way to extract specific values from a string? let temp = 'Hi {{username}}, Your request with request id: {{requestId}} has been processed. Please contact your nearest shop.' Desiring an array like this from the string: ['user ...

Issue encountered when exporting with node and mongoose

After creating some schema and exporting the model, here is the code: var mongoose = require('mongoose'); var specSchema = new mongoose.Schema({ name: String, description:String }); var qualSchema = new mongoose.Schema({ name: Str ...

Is there a way to call class methods from external code?

I am seeking clarification on Class files. Below is an example of a Class that I have: class CouchController { constructor(couchbase, config) { // You may either pass couchbase and config as params, or import directly into the controller ...

The gulp-pug plugin is malfunctioning and displaying an error message stating "unexpected token 'indent'"

There seems to be an issue with gulp-pug indicating an unexpected token "indent" Please refer to the images below for further details: gulp code and nodejs command prompt index.pug and nodejs command prompt package.json and nodejs command prompt I am ...

When attempting to compile Typescript code, error TS1128 occurs indicating a missing declaration or statement. However, the code functions correctly when executed through a server

Currently, I'm in the process of developing a project using Angular2. As part of this project, I have created a primary Component class which serves as a central piece: import { Component, OnInit} from '@angular/core'; import { submitServi ...

NodeJS package 'jquery' npm not functioning properly (issue with $.on())

I've successfully installed and loaded jquery by using $ = require('jquery'); However, when I attempt to utilize it: app.get('/', function (req, res) { res.render('index'); $.on('ready', function () { ...

Deleting multiple paths in Firebase using the orderByChild() method

When a user decides to delete their account, the challenge arises in cleaning up all the data in the RTDB. This process is straightforward except for certain nodes where orderByChild is required to access them. Is it possible to achieve this within an ato ...

When restarting nginx, Angular fails to display the index page

On my VPS server, I have an application with the backend coded in node.js and the frontend in Angular. After restarting nginx, I encountered some issues where my API stopped working on HTTPS and only functioned on HTTP (previously, I was able to make requ ...

receiving a pair of components instead of just one

Here is the code for router.js: import React from 'react'; import { Route } from 'react-router-dom'; import CommentList from './containers/commentview'; import CommentDetalList from './containers/commentdetailview'; ...

The constructor error in ng-serve signalizes an issue in

Currently, I am developing an AngularJS application. However, when attempting to start the dev server, I encountered an issue with my ng serve command: https://i.stack.imgur.com/QujSe.png ...

What could be causing my Javascript prompts to not appear in my Express.IO .ejs file?

I am fairly new to JavaScript and exploring Node with Express.IO. I'm currently working on a project that involves tracking real-time connections made by different 'users' to the server. However, I've encountered an issue where my promp ...

Troubleshooting Node.js Serve-static Failure

I'm currently facing an issue related to routing and displaying static files. Here's how my directory structure looks like: app/ --app.js —-public/ —-js/ —-main.js —-views/ —-pages/ —-index.jade This is the way I ha ...

The flattening of dependencies in npm 3 may not always be implemented consistently

I have encountered a situation where I have 3 dependencies, all of which reference esprima-fb. Surprisingly, they all resolve to version 15001.1001.0-dev-harmony-fb. What puzzles me is that instead of finding esprima-fb at the top level of the node_module ...

Using node express to proxy json requests

In order to proxy requests from a web server to an API server, I am using the code snippet below in my node-express application: app.use('/api', function(req, res) { var url = 'http://my.domain.com/api' + req.url; req.pipe(request( ...

phantomjs rate limiting in Bitbucket

My continuous integration builds are consistently failing with this error message: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="54243c353a203b393e2714657a6d7a63796561">[email protected]</a> install /home/t ...