Ch. 12 Piping Streams Client/Server not working for me?
Hello,
I'm doing the LFW211 Node.JS Applications Certification course, and I'm on Chapter 12 about Streams. In the last section on Piping Streams, the course re-writes the previous Duplex Streams Client/Server example. I tried copying this code into two different files, a server-piping.js file and a client-piping.js file. I've tried running this, but it never works the way you show in that Chapter 12 on Streams.
First, my set-up — I'm on a 2022 MacBook Air with the Apple Silicon M2 chip, 24 GB of RAM and MacOS Sonoma v14.2.1. I'm running Node.JS v20.11.0 on this MacBook.
In your example, you say the result of running the server and then the client should be —

Here's my server-piping.js file —
'use strict'
const net = require('net')
const { pipeline } = require('stream')
const { createTransformStream } = require('./client-piping.js')
net.createServer((socket) => {
const transform = createTransformStream()
const interval = setInterval(() => {
socket.write('beat')
}, 1000)
pipeline(socket, transform, socket, (err) => {
if (err) {
console.error('There was a socket error closing the pipelin: ', err)
}
clearInterval(interval)
})
}).listen(3000)
and here's my client-piping.js file —
'use strict'
const { Transform } = require('stream')
const { scrypt } = require('crypto')
function createTransformStream() {
return new Transform({
decodeStrings: false,
encoding: 'hex',
transform(chunk, enc, next) {
scrypt(chunk, 'a-salt', 32, (err, key) => {
if (err) {
next(err)
return
}
next(null, key)
})
}
})
}
module.exports = createTransformStream
When I run the server and then the client files, it just sits there for many minutes, up to 10 minutes, then I get the following —
$ node server-piping.js
/Users/faddah/Documents/code/learning/LinuxFound-OpenJS/NodeJSApps/labs-dec-2023/ch-12/streams/server-piping.js:25
const transform = createTransformStream()
^
ReferenceError: createTransformStream is not defined
at Server.<anonymous> (/Users/faddah/Documents/code/learning/LinuxFound-OpenJS/NodeJSApps/labs-dec-2023/ch-12/streams/server-piping.js:25:20)
at Server.emit (node:events:518:28)
at TCP.onconnection (node:net:2163:8)
Node.js v20.11.0
i get this, event though i've done a module.exports = createTransformStream" in theclient-piping.jsfile and imported it in the top of theserver-piping.js` file. I would just like to see this code fun as it says it should run in the chapter.
Also, I have now asked about three or four questions in this forum in the last few weeks, and absolutely NONE of them have been answered by anyone. I understand already that this is a Community forum and Linux Foundation / OpenJS folk or the instructor are not often on here nor are required to answer, and it's a Community forum with answered supplied by the User Community; however, I find it really strange that I've posed these questions with absolutely no response, but others in this forum have had their questions / discussion readily answered since then. Could I please get someone to look at this question and the previous quesitons I've posed here on this forum and get some answers, please?
best,
faddah
Answers
Categories
- All Categories
- 175 LFX Mentorship
- 175 LFX Mentorship: Linux Kernel
- 745 Linux Foundation IT Professional Programs
- 372 Cloud Engineer IT Professional Program
- 168 Advanced Cloud Engineer IT Professional Program
- 73 DevOps IT Professional Program - Discontinued
- 3 DevOps & GitOps IT Professional Program
- 98 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- AI & ML Training
- Blockchain & Decentralized Identity Training
- Cloud & Containers Training
- Cybersecurity Training
- DevOps & Site-Reliability Training
- Linux Kernel Development Training
- Networking Training
- Open Source Best Practice Training
- System Administration Training
- System Engineering Training
- Web & Application Development Training
- 2 LFD103-JP クラス フォーラム
- 4 LFD210-CN Class Forum
- 764 LFD259 Class Forum
- 681 LFS101 Class Forum
- 2 LFS158-JP クラス フォーラム
- 162 LFS207 Class Forum
- 3 LFS207-DE-Klassenforum
- 4 LFS207-JP クラス フォーラム
- 61 LFS241 Class Forum
- 52 LFS242 Class Forum
- 42 LFS243 Class Forum
- 19 LFS244 Class Forum
- 4 LFS250-JP クラス フォーラム
- 166 LFS253 Class Forum
- 19 LFS256 Class Forum
- 1.4K LFS258 Class Forum
- 165 LFS261 Class Forum
- 26 LFS267 Class Forum
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 105 Mobile Computing
- 18 Android
- 72 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 944 Programming and Development
- 310 Kernel Development
- 616 Software Development
- 976 Software
- 368 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
