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
- 178 LFX Mentorship
- 178 LFX Mentorship: Linux Kernel
- 772 Linux Foundation IT Professional Programs
- 382 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 102 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 7 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 19 Cloud & Containers Training
- 2 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 2 Networking Training
- 2 Open Source Best Practice Training
- 5 System Administration Training
- 1 System Engineering Training
- 3 Web & Application Development Training
- 797 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 91 Storage
- 771 Linux Distributions
- 81 Debian
- 68 Fedora
- 23 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 467 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 99 Linux Security
- 79 Network Management
- 101 System Management
- 46 Web Management
- 136 Mobile Computing
- 20 Android
- 101 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 402 Off Topic
- 125 Introductions
- 33 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 709 Software Development
- 1K Software
- 416 Applications
- 182 Command Line
- 5 Compiling/Installing
- 71 Games
- 319 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 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)
