Skip to content
SPONSORS
Picture of Geoff St. Pierre
Geoff St. Pierre

Installing Node in Your Lando PHP Service

Some frontend tooling kits like Emulsify or Pattern Lab may assume that composer/php can invoke yarn/npm/node and vice-versa. This pattern, sadly, is fundamentally at odds with Lando's one-thing-per-container model.

You can, however, get around it by installing the needed dependencies directly in the service that requires them.

We've found installing node inside a Lando PHP service to generally be the path of least resistance.

1. Using build steps

Below is an example that installs node12 using build-steps.

yaml
services:
  myservice:
    type: php
    build_as_root:
      # Note that you will want to use the script for the major version of node you want to install
      # See: https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
      - curl -sL https://deb.nodesource.com/setup_12.x | bash -
      - apt-get install -y nodejs
tooling:
  node:
    service: myservice
  npm:
    service: myservice

You can verify with:

bash
lando node -v
lando npm -v

2. Extending a Dockerfile

If you are planning to extend your service with additional build steps or would like to cache the build steps for a faster lando rebuild you should instead consider extending with a Dockerfile as in the example below:

.lando.yml

yaml
services:
  myservice:
    type: php:custom
    via: cli
    overrides:
      image: lando/php:7.4-with-node12
      build:
        context: ./
        dockerfile: Dockerfile.node
tooling:
  node:
    service: myservice
  npm:
    service: myservice

Dockerfile.node

docker
FROM devwithlando/php:7.4-apache-2

# Choose the major node version
ENV NODE_VERSION=12

# Install node
RUN curl -sL "https://deb.nodesource.com/setup_${NODE_VERSION}.x" | bash - \
  && apt-get install -y nodejs

Again, you can verify with:

bash
lando node -v
lando npm -v