Building and Testing Node.js¶
This guide shows you how to build and test a Node.js application.
Example Workflow¶
name: nodejs-build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run build --if-present
- run: npm test
Detailed Explanation¶
- Use Node.js:
actions/setup-nodeinstalls the specified Node.js version. - npm ci: Installs dependencies strictly from
package-lock.json(faster and more reliable for CI thannpm install). - npm run build: Runs the build script defined in your
package.json. - npm test: Runs the test script.
📬 DevopsPilot Weekly — Learn DevOps, Cloud & Gen AI the simple way.
👉 Subscribe here