allie
0
Q:

how to create a server in node js

// code by VARSHITH REDDY SATTI
// to create a server in node.js you should.
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write("write html code to display you test")
  res.end();
}).listen(8080);
// save this as httpServer.js
// run this by typing node httpServer.js in the command line
// to acess your server got to http://localhost:8080
2
var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the 
2
const http = require("http");
const port = 3000; // Replace this if you want, this is just used for most examples

http.createServer("/", (req, res) => {
  res.writeHead(200);
  res.write("Hello World");
  res.end();
});

http.listen(port, console.log(`Server started at http://localhost:${port}`));
-1

New to Communities?

Join the community