Create a custom Node.js application

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

Many users run a Bitnami stack as a development environment for their own projects (as opposed to running third-party applications). To create a custom Node.js application from scratch, follow the steps below. These steps assume that your application will live in the installdir/apps/myapp/ directory:

  • Run the following commands to create the directories:

      $ sudo mkdir -p installdir/apps/myapp
      $ sudo mkdir installdir/apps/myapp/conf
      $ sudo mkdir installdir/apps/myapp/htdocs
  • Create a new Node.js project with Express:

      $ cd installdir/apps/myapp/htdocs
      $ sudo express --view pug
      $ sudo npm install
  • Start the Express server:

      $ cd installdir/apps/myapp/htdocs
      $ DEBUG=sample:* ./bin/www

    Alternatively, use the following command to start the server and keep it running even after your server session ends. Replace FILE with the correct filename for your application.

      $ forever start FILE.js

    NOTE: Although your application is now available, you may not be able to access it immediately. This is because the Express server runs on port 3000 by default, and Bitnami stacks on some platforms have this port closed for security reasons. To access the application, you will need to create an SSH tunnel to the port.

  • Create and edit the installdir/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:

      Include "installdir/apps/myapp/conf/httpd-app.conf"
  • Create and edit the installdir/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application’s requirements.

      ProxyPass /
      ProxyPassReverse /

    NOTE: 3000 is the default port for the Express server. If you have customized your application to use a different port, change it here as well.

  • Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

      Include "installdir/apps/myapp/conf/httpd-prefix.conf"
  • Restart the Apache server:

      $ sudo installdir/ restart apache
Last modification April 22, 2020