Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/pr-node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
- examples/18
- examples/19
- examples/20
- examples/21
- examples/22
- examples/23
lando-version:
- 3-edge
- 3-stable
os:
- ubuntu-24.04
node-version:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added support for Node 23, 22 and 21. [#92](https://github.com/lando/node/issues/92)

## v1.3.3 - [December 6, 2024](https://github.com/lando/node/releases/tag/v1.3.3)

* Updated the version index.md to get Docuverse page to build correctly.
Expand Down
27 changes: 27 additions & 0 deletions builders/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ const _ = require('lodash');

// Constants
const supportedVersions = [
'23',
'23.5',
'23.4',
'23.3',
'23.2',
'23.1',
'22',
'22.12',
'22.11',
'22.10',
'22.9',
'22.8',
'22.7',
'22.6',
'22.5',
'22.4',
'22.3',
'22.2',
'22.1',
'21',
'21.7',
'21.6',
'21.5',
'21.4',
'21.3',
'21.2',
'21.1',
'20',
'20.9',
'20.8',
Expand Down
2 changes: 1 addition & 1 deletion docs/caveats.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Lando will set the `PATH` hierarchy for this service as follows:
]
```

This is useful to note if you are not using absolute paths in any [tooling routes](https://docs.lando.dev/core/v3/tooling.html) and are getting the unexpected version of a particular utility.
This is useful to note if you are not using absolute paths in any [tooling routes](https://docs.lando.dev/landofile/tooling.html) and are getting the unexpected version of a particular utility.
16 changes: 8 additions & 8 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ description: Learn how to configure the Lando Node service.

# Configuration

Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/core/v3/services/lando.html) to get a good handle on how the magicks work.
Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/services/lando-3.html) to get a good handle on how the magicks work.

Also note that options, in addition to the [build steps](https://docs.lando.dev/core/v3/services/lando.html#build-steps) and [overrides](https://docs.lando.dev/core/v3/services/lando.html#overrides) that are available to every service, are shown below:
Also note that options, in addition to the [build steps](https://docs.lando.dev/services/lando-3.html#build-steps) and [overrides](https://docs.lando.dev/services/lando-3.html#overrides) that are available to every service, are shown below:

```yaml
services:
Expand Down Expand Up @@ -47,7 +47,7 @@ services:

## Using SSL

Also note that `ssl: true` will only generate certs in the [default locations](https://docs.lando.dev/core/v3/security.html) and expose port `443`. It is up to the user to use the certs and secure port correctly in their application like the `node` snippet below:
Also note that `ssl: true` will only generate certs in the [default locations](https://docs.lando.dev/config/security.html) and expose port `443`. It is up to the user to use the certs and secure port correctly in their application like the `node` snippet below:

```js
// Get our key and cert
Expand Down Expand Up @@ -80,9 +80,9 @@ services:
You can also use the `globals` key if you need to install any [global node dependencies](https://docs.npmjs.com/cli/install/). This follows the same syntax as your normal [`package.json`](https://docs.npmjs.com/files/package.json/) except written as YAML instead of JSON.

::: tip Use package.json if you can!
While there are some legitimate use cases to globally install a node dependency, it is almost always preferred to install using your applications normal `package.json` and then running either `lando npm` or `lando yarn` or alternatively setting up a [build step](https://docs.lando.dev/core/v3/services/lando.html#build-steps) that will automatically run before your app starts up.
While there are some legitimate use cases to globally install a node dependency, it is almost always preferred to install using your applications normal `package.json` and then running either `lando npm` or `lando yarn` or alternatively setting up a [build step](https://docs.lando.dev/services/lando-3.html#build-steps) that will automatically run before your app starts up.

Note that both `lando yarn` and `lando npm` are not provided out of the box by the `node` service and need to be manually added by configuring your app's [tooling](https://docs.lando.dev/core/v3/tooling.html).
Note that both `lando yarn` and `lando npm` are not provided out of the box by the `node` service and need to be manually added by configuring your app's [tooling](https://docs.lando.dev/landofile/tooling.html).
:::

An example of globally installing the `latest` `gulp-cli` is shown below:
Expand All @@ -96,7 +96,7 @@ services:
command: npm start
```

An example of using a [build step](https://docs.lando.dev/core/v3/services/lando.html#build-steps) to automatically `npm install` your dependencies before your app invokes `yarn start-app` is shown below:
An example of using a [build step](https://docs.lando.dev/services/lando-3.html#build-steps) to automatically `npm install` your dependencies before your app invokes `yarn start-app` is shown below:

```yaml
services:
Expand Down Expand Up @@ -127,7 +127,7 @@ lando node
lando yarn
```

Lando tooling is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/core/v3/tooling.html) of its cool features.
Lando tooling is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/landofile/tooling.html) of its cool features.

## Adding routing

Expand All @@ -140,4 +140,4 @@ proxy:
- something.else.local
```

Lando proxying is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/core/v3/proxy.html) of its cool features.
Lando proxying is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/landofile/proxy.html) of its cool features.
6 changes: 3 additions & 3 deletions docs/guides/frontend-tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ When you're done, you should be able to distribute your Lando app with a full se

## Add Node Service

Assuming you're starting with a "Lando-ized" app, open the `.lando.yml` file in the root of your app directory. In this example we'll assume you're using a very basic [LAMP](https://docs.lando.dev/core/v3/lamp.html) recipe.
Assuming you're starting with a "Lando-ized" app, open the `.lando.yml` file in the root of your app directory. In this example we'll assume you're using a very basic [LAMP](https://docs.lando.dev/plugins/lamp/) recipe.

To install our frontend tooling we need to be able to run Node. Fortunately it's very easy for us to add a basic Node service to our app:

Expand Down Expand Up @@ -61,12 +61,12 @@ You can do the same thing for any NPM project; for example Grunt would be `grunt
Note we've now added a another command to `build` to automatically run `gulp` every time we start the app. This, of course, assumes that the default `gulp` task is defined otherwise you should expect your build step to fail.

::: tip Package Versions Are Fully Armed and Customizable
You can lock your app tooling to whatever package version you like. Don't use node:6.10? Change to one of the other available versions in the [service documentation](https://docs.lando.dev/core/v3/node.html). And you're free to download whatever version of a global service your heart desires. For example, if you want to lock your team to something more stable than the latest gulp-cli, change that entry in `globals` to `gulp-cli:1.3.0`.
You can lock your app tooling to whatever package version you like. Don't use node:6.10? Change to one of the other available versions in the [service documentation](https://docs.lando.dev/plugins/node/). And you're free to download whatever version of a global service your heart desires. For example, if you want to lock your team to something more stable than the latest gulp-cli, change that entry in `globals` to `gulp-cli:1.3.0`.
:::

## Making Tooling Available on the CLI

Almost there! All our services are installed, but how do we run a command on the fly, say starting a watch task or running `lando npm install hot-new-thing` to start experimenting with a new package? We could SSH into our node container, but that's SO 2016. Instead, we'll expose our new tooling via the CLI by adding this [`tooling`](https://docs.lando.dev/core/v3/tooling.html) section to our `.lando.yml` file:
Almost there! All our services are installed, but how do we run a command on the fly, say starting a watch task or running `lando npm install hot-new-thing` to start experimenting with a new package? We could SSH into our node container, but that's SO 2016. Instead, we'll expose our new tooling via the CLI by adding this [`tooling`](https://docs.lando.dev/landofile/tooling.html) section to our `.lando.yml` file:

```yml
tooling:
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/using-compass.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ However, if you cannot do this you may run into some issues running `compass` in

You can, however, get around it by installing `ruby` and `compose` directly in the `node` service that requires them.

Below is an example that installs `ruby` and `compass` using [build-steps](https://docs.lando.dev/core/v3/services/lando.html#build-steps).
Below is an example that installs `ruby` and `compass` using [build-steps](https://docs.lando.dev/services/lando-3.html#build-steps).

```yaml
services:
Expand Down
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ next: ./config.html

[Node.js](https://nodejs.org/en/) is a JavaScript runtime built on Chrome's V8 JavaScript engine and uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Beyond running web applications, it is also commonly used for frontend tooling.

You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/core/v3/services/lando.html) top-level config in your [Landofile](https://docs.lando.dev/core/v3).
You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/services/lando-3.html) top-level config in your [Landofile](https://docs.lando.dev/landofile/).

```yaml
services:
Expand All @@ -19,14 +19,17 @@ services:

## Supported versions

* [23](https://hub.docker.com/_/node)
* [22](https://hub.docker.com/_/node)
* [21](https://hub.docker.com/_/node)
* [20](https://hub.docker.com/_/node)
* [19](https://hub.docker.com/_/node)
* [18](https://hub.docker.com/_/node)
* [17](https://hub.docker.com/_/node)
* [16](https://hub.docker.com/_/node)
* [15](https://hub.docker.com/_/node)
* **[14](https://hub.docker.com/_/node)** **(default)**
* [custom](https://docs.lando.dev/core/v3/services/lando.html#overrides)
* [custom](https://docs.lando.dev/services/lando-3.html#overrides)

## Legacy versions

Expand Down
3 changes: 3 additions & 0 deletions examples/21/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
package-lock.json
37 changes: 37 additions & 0 deletions examples/21/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: lando-node-21
services:
defaults:
type: node:21
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js
cli:
type: node
compass:
type: node:21
globals:
grunt-cli: latest
custom:
type: node:21
ssl: true
globals:
gulp-cli: latest
port: 3000
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js
custom2:
type: node:21.5.0
ssl: 4444
port: 3000
build:
- yarn
command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js
tooling:
grunt:
service: compass

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/node": ../..
83 changes: 83 additions & 0 deletions examples/21/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Node 21 Example

This example exists primarily to test the following documentation:

* [Node 14-21 Service](https://docs.devwithlando.io/tutorials/node.html)
* [Installing compass in your node service](https://docs.lando.dev/guides/using-compass-on-a-lando-node-service.html)

## Start up tests

Run the following commands to get up and running with this example.

```bash
# Should start up successfully
lando poweroff
lando start
```

## Verification commands

Run the following commands to validate things are rolling as they should.

```bash
# Should use 21.x as the default version
lando exec defaults -- "env | grep NODE_VERSION=21."

# Should use a user specified version if given
lando exec custom -- "env | grep NODE_VERSION=21."

# Should use a user specified patch version if given
lando exec custom2 -- "env | grep NODE_VERSION=21.5.0"

# Should serve over port 80 by default
lando exec defaults -- "curl http://localhost | grep tune"

# Should set NODE_EXTRA_CA_CERTS with lando domain CA
lando exec defaults -- "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT"

# Should only serve over http by default
lando exec defaults -- "curl https://localhost" || echo $? | grep 7

# Should serve over specified ports if given
lando exec custom -- "curl http://localhost:3000 | grep tune"

# Should serve over https is ssl is set by user
lando exec custom -- "curl https://localhost | grep tune"

# Should servce over a custom https port if ssl is set to a specific port
lando exec custom2 -- "curl https://localhost:4444 | grep DANCING"

# Should run as root if it needs to
lando exec defaults -- "ps -a -u root" | grep "node" | wc -l | grep 2
lando exec custom -- "ps -a -u root" | grep "node" | wc -l | grep 2

# Should run as node if it can
lando exec custom2 -- "ps -a -u node" | grep "node" | wc -l | grep 2

# Should install global dependencies if specified by user and have them available in PATH
lando exec custom -- "gulp -v"
lando exec custom -- "which gulp | grep /var/www/.npm-global"

# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones
lando exec custom -- "npm install gulp-cli --no-save"
lando exec custom -- "gulp -v"
lando exec custom -- "which gulp | grep /app/node_modules/.bin"
lando exec custom -- "npm uninstall gulp-cli"
lando exec custom -- "which gulp | grep /var/www/.npm-global"

# Should not serve port for cli
lando exec cli -- "curl http://localhost" || echo $? | grep 7

# Should install gruntcli
lando grunt -V
```

## Destroy tests

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
27 changes: 27 additions & 0 deletions examples/21/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "node-lando",
"version": "1.0.0",
"description": "Node example for Lando",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/lando/lando/tree/master/examples/node"
},
"keywords": [
"node",
"docker",
"localdev"
],
"author": "Mike Pirog",
"license": "MIT",
"dependencies": {
"express": "^4.19.2"
},
"devDependencies": {
"grunt-contrib-compass": "^1.1.1",
"nodemon": "^3.0.1"
}
}
28 changes: 28 additions & 0 deletions examples/21/src/app-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Lando node express example
*
* @name taylorswift
*/

'use strict';

// Load modules
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();

// Create our HTTPS server options
const key = fs.readFileSync('/certs/cert.key');
const cert = fs.readFileSync('/certs/cert.crt');

// Create our servers
https.createServer({key, cert}, app).listen(4444);
http.createServer(app).listen(3000);

// Basic HTTP response
app.get('/', (req, res) => {
res.header('Content-type', 'text/html');
return res.end('<h1>DANCING DANCING STARLIGHT</h1>');
});
21 changes: 21 additions & 0 deletions examples/21/src/app-http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Lando node express example
*
* @name taylorswift
*/

'use strict';

// Load modules
const http = require('http');
const express = require('express');
const app = express();

// Create our server
http.createServer(app).listen(80);

// Basic HTTP response
app.get('/', (req, res) => {
res.header('Content-type', 'text/html');
return res.end('<h1>I said "Oh my!" What a marvelous tune!!!</h1>');
});
Loading
Loading