man
man

Reputation: 1

i have error its show a syntax error in line 1 character 1

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {//i create the server
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');//log to the console
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

//and its dont work its show me a syntax error //if someone can tell me how to fix this

Upvotes: 0

Views: 304

Answers (1)

Sryyt
Sryyt

Reputation: 11

Don't double click on your js file, you have to launch it using nodejs :

  1. Download nodejs
  2. Open a terminal
  3. Move to your current directory (where the file is located) with the cd command
  4. Type "node yourfile.js"

You will have the output of your program in the terminal.

Upvotes: 1

Related Questions