G
G
gleendo2017-04-24 12:30:10
JavaScript
gleendo, 2017-04-24 12:30:10

Why doesn't the simplest node.js code run?

I started reading the tutorial, but for some reason the first example from the book does not start. What is the problem?

const http = require(`http`);

http.createServer((request, response) => console.log(`works...`));

http.listen(8080);

stacktrace:
C:\Users\iamevg_\Desktop>node app.js
C:\Users\iamevg_\Desktop\app.js:5
http.listen(8080);
     ^

TypeError: http.listen is not a function
    at Object.<anonymous> (C:\Users\iamevg_\Desktop\app.js:5:6)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vishnevsky, 2017-04-24
@evgeniy8705

const http = require('http')
const server = new http.Server((req,res) => console.log('works...'));
server.listen(8000)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question