NodeJS/Express web application
Set up your component repository to use the node/npm/express stack. With the Docker Generic scaffolder, developers can create a Dockerfile that allows setting up a NodeJS application that starts an Express server.
Prerequisites
- Application previously created to hold the NodeJS component that we will add.
- Basic knowledge of Dockerfile in case the provided Dockerfile needs customization.
- node & npm
- On your local computer, you must use npm v7 or posterior versions. As a matter of fact, this repository uses version 2 of
package-lock.json
. While version 2 is backward compatible with version 1 (used by npm v5 and v6), you should upgrade your local npm version to at least v7 to avoid possible issues. - CodeNOW's deployment will use Node v18 (cf. Dockerfile). In order to have deployment environments as close as possible to your local environment, we recommend you to use the same node version.
- On your local computer, you must use npm v7 or posterior versions. As a matter of fact, this repository uses version 2 of
- git is installed.
Steps
The quickest way to set up a NodeJS Express web application is as follows:
- Navigate to your application.
- Create a component with the Docker Generic scaffolder.
- Clone the component's Git repository to your local machine.
- Clone CodeNOW's NodeJS/Express scaffolding repository to your local machine.
- Copy the contents of the current repository (now on your local machine) to the component's Git repository.
- NOTE: do not copy the
.git
file.
You are all set! Commit those changes; push; you are then ready to build and deploy your NodeJS/Express component in CodeNOW. The scaffolding code reflects the following configuration choices:
- Programs will run with NodeJS version 18.
- Node will run
./bin/www
on startup. - The
npm
package manager is used. - The application uses the Express web server framework (version 4.16).
package.json
holds the application dependencies and their versions.- Your Express/NodeJS code is in the repository's home directory.
- Pug/Jade is used as a templating language for web pages.
- The Express's Router module is used for routing.
- The application starts on port 80.
Customize further to reflect additional constraints or requirements:
- Update the version of the dependencies.
- Update the dependencies.
- Add deployment configuration files in the
/codenow/config/
folder. Files in this folder are deployed with the application so the application can access them at runtime. For more information, see Deployment configurations.
Interesting links: