Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Docker mounted volume removes node_modules
# Set the base image to stable version of node
FROM node:0.12.2
# Install nodemon
RUN npm install -g nodemon
# Provides cached layer for node_modules
COPY package.json /tmp/package.json
RUN cd /tmp && npm install --production
RUN mkdir -p /app && cp -a /tmp/node_modules /app/
RUN mkdir /app/.tmp
# Define working directory
COPY . /app
# Expose port
# Run app using nodemon
CMD ["nodemon", "/app/index.js"]
* This file is used for creating a symlink between the actual ./node_modules folder
* and the ./src/node_modules "folder".
* This is due to being able to both run the app smoothly in a local and containerized environment.
var fs = require('fs');
// Paths
var NODE_MODULES = '../node_modules'
var SRC_NODE_MODULES = './src/node_modules';
// Check if the symlink is already existing..
fs.exists(SRC_NODE_MODULES, function(exists) {
// ?: Is it NOT existing?
if (!exists) {
// -> Nope, then create it and launch the server
// E -> The symlink exists!
console.log('! SYMLINK exists, recreate it..')
// Remove the existing link (why? Because we do not know if it was created locally or in a container)
fs.unlink(SRC_NODE_MODULES, function(err) {
if (err) return console.log(err);
// Double check that the link was removed
fs.exists(SRC_NODE_MODULES, function(exists) {
console.log('! SYMLINK was ' + (exists ? 'NOT DELETED!' : 'deleted successfully..'));
// Was it removed?
if (exists) {
// -> NO! Then abort mission!
return console.log('! Aborting server launch..')
// E -> It was removed successfully. Re-create it and launch the server
var createSymLink = function(callback) {
fs.symlink(NODE_MODULES, SRC_NODE_MODULES, 'dir', function(err) {
if (err) return console.log(err);
console.log('! SYMLINK created!')
var launchServer = function() {
console.log('! Launching server..')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment