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
ipe(process.stdout)).end()
^

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?

Answers

  • Posts: 160

    @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?)

  • Posts: 33

    @xdxmxc Yes that would be a good idea.

    Just got stuck on this for a while, ending up choosing curl instead. Anything to keep the learning process moving forward without unnecessary interruptions is super!

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training