Y
Y
ymenaidtopa2021-11-11 20:31:01
JavaScript
ymenaidtopa, 2021-11-11 20:31:01

Do you get an error when using the command?

The code:

const http = require('http');
const port = 3001;
const server = http.createServer();

server**on('request'** (request, response) => {
    console.log(`URL: ${request.url}`);
    response.end('Hello, server!')
})

server.listen(port, (error) => {
    if (error) return console.log(`Error: ${error}`);

    console.log(`Server is listening on port ${port}`)
})

Mistake:
C:\Users\User_ml\Desktop\FirstApi\express-api>node hello-server.js
C:\Users\User_ml\Desktop\FirstApi\express-api\hello-server.js:5
server**on('request'** (request, response) => {
                    ^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Malformed arrow function parameter list
[90m    at Object.compileFunction (node:vm:352:18)[39m
[90m    at wrapSafe (node:internal/modules/cjs/loader:1031:15)[39m
[90m    at Module._compile (node:internal/modules/cjs/loader:1065:27)[39m
[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)[39m
[90m    at Module.load (node:internal/modules/cjs/loader:981:32)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)[39m
[90m    at node:internal/main/run_main_module:17:47[39m

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2021-11-11
@ymenaidtopa

The console shows you the location of the error. Do any of them bother you **? It should be like this:

server.on('request', (request, response) => {
    console.log(`URL: ${request.url}`);
    response.end('Hello, server!')
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question