diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml
new file mode 100644
index 000000000..1b9ffa341
--- /dev/null
+++ b/.github/workflows/examples.yml
@@ -0,0 +1,32 @@
+# This workflow will run the examples provided in the examples folder
+name: examples
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ nodejs:
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ node-version:
+ - 10.x
+ - 12.x
+ - 14.x
+ - 16.x
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v2
+ with:
+ node-version: ${{ matrix.node-version }}
+ - run: npm install
+ working-directory: examples/nodejs
+ - run: npm run test
+ working-directory: examples/nodejs
diff --git a/examples/nodejs/.gitignore b/examples/nodejs/.gitignore
new file mode 100644
index 000000000..d5f19d89b
--- /dev/null
+++ b/examples/nodejs/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+package-lock.json
diff --git a/examples/nodejs/.npmrc b/examples/nodejs/.npmrc
new file mode 100644
index 000000000..43c97e719
--- /dev/null
+++ b/examples/nodejs/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json
new file mode 100644
index 000000000..357e33282
--- /dev/null
+++ b/examples/nodejs/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "@xmldom/xmldom-example-nodejs",
+ "private": true,
+ "description": "Show how to use xmldom in a nodejs project",
+ "main": "src/index.js",
+ "scripts": {
+ "test": "node src/index.js"
+ },
+ "keywords": [
+ "test",
+ "commonjs",
+ "nodejs"
+ ],
+ "author": "",
+ "license": "MIT",
+ "dependencies": {
+ "@xmldom/xmldom": "file:../.."
+ }
+}
diff --git a/examples/nodejs/src/index.js b/examples/nodejs/src/index.js
new file mode 100644
index 000000000..ff8c7353f
--- /dev/null
+++ b/examples/nodejs/src/index.js
@@ -0,0 +1,15 @@
+const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')
+
+const source = `
+ test
+
+`
+
+const doc = new DOMParser().parseFromString(source, 'text/xml')
+
+const serialized = new XMLSerializer().serializeToString(doc)
+
+if (source !== serialized) {
+ console.error(`expected\n${source}\nbut was\n${serialized}`)
+ process.exit(1);
+}
diff --git a/readme.md b/readme.md
index b42479811..51a1fa0b2 100644
--- a/readme.md
+++ b/readme.md
@@ -40,26 +40,21 @@ This project was forked from it's [original source](https://github.com/jindw/xml
### Example:
+[In NodeJS](examples/nodejs/src/index.js)
```javascript
-const { DOMParser } = require('@xmldom/xmldom')
-
-const doc = new DOMParser().parseFromString(
- '\n' +
- '\ttest\n' +
- '\t\n' +
- '\t\n' +
- '',
- 'text/xml'
-)
-doc.documentElement.setAttribute('x', 'y')
-doc.documentElement.setAttributeNS('./lite', 'c:x', 'y2')
-console.info(doc)
-
-const nsAttr = doc.documentElement.getAttributeNS('./lite', 'x')
-console.info(nsAttr)
+const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')
+
+const source = `
+ test
+
+`
+
+const doc = new DOMParser().parseFromString(source, 'text/xml')
+
+const serialized = new XMLSerializer().serializeToString(doc)
```
-Note: in Typescript and ES6 you can use the import approach, as follows:
+Note: in Typescript ~and ES6~(see #316) you can use the `import` approach, as follows:
```javascript
import { DOMParser } from '@xmldom/xmldom'