Welcome to the Linux Foundation Forum!

Creating a Web Server with Node Core (3) - Testing POST eval not working

This code snippet returns error:
node -e "ht‌tp.request('ht‌tp://localhost:3000', {method: 'POST'}, (res) => res.pipe(process.stdout)).end()"

PS C:\LFW212\labs\ch-3\http-web-server> node -e "ht‌tp.request('ht‌tp://
localhost:3000', {method: 'POST'}, (res) => res.pipe(process.stdout)).end()"
ht‌tp.request('ht‌tp://localhost:3000', {method: 'POST'}, (res) => res.p

ReferenceError: ht‌tp is not defined
at eval:1:1
at Script.runInThisContext (node:vm:129:12)
at Object.runInThisContext (node:vm:305:38)
at node:internal/process/execution:76:19
at eval-wrapper:6:22
at evalScript (node:internal/process/execution:75:60)
at node:internal/main/eval_string:27:3

I can test with separate file "nonget.js" containing:

const http = require('http')

http.request('http://localhost:3000/', { method: 'POST' }, (res) => res.pipe(process.stdout)).end()

What am I doing wrong in the CLI?


  • xdxmxc
    xdxmxc Posts: 61

    @mfnodes there's a hidden character between the the two t's of http - it may have come from copy pasting from the learning platform @fcioanca can we please make sure that copy-pasting code doesn't insert hidden characters anywhere (starting with this case?)


Upcoming Training