Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node server

// Create node.js server with routing. Create server.js file:
const http = require("http");

const server = http.createServer((req, res) => {
  // called every time request comes to the server (e.g. when you refresh page)
  console.log("request made: ", req.url); 
  
  // define what type of content you are sending (plain text or html or JSON file, etc.)
  res.setHeader("Content-Type", "text/html");

  // display response in browser
  res.write("<h1>Ladies and Gentlemans</h1>");
  res.write("<h2>We're in!</h2>");
  res.end();
});

server.listen(3000, "localhost", () => {
  console.log("listening for requests on port 3000"); // you can see this not in browser console, but in terminal
});

// Now, in terminal go to directory with server.js and run:
node server.js
// You can see the results in browser at http://localhost:3000

// NOTE: If you want to handle different adresses/pages/routes 
// like /about, /contact or /blog search in google/grepper for "node server with routes"

// NOTE: If you want to run external index.html file search in google/grepper for "node server index.html"
Comment

node js server

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
Comment

Node.js Web Server

var http = require('http');

http.createServer(function (req, res) {
	res.write('Hello World!');
    res.end();
}).listen(8080);
Comment

how to create node js server

//HTTP MODULE NODE.JS
var http = require('http');
var server = http.createServer(function(req, res){
  //write code here
});
server.listen(5000); 
Comment

create node js server

import express from 'express';
const server = express();

const port = 8080;

server.get('/', (req, res) => {
  return res.send('Hello, Express.js!');
})

server.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
Comment

start node.js server

## Make sure you run this command in the app directory.
node .
Comment

how to create node js server

const http = require('node:http');

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

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, programmer!');
});

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

PREVIOUS NEXT
Code Example
Javascript :: reactsj substring 
Javascript :: reactjs cut part of string 
Javascript :: how to remove duplicate object in array javascript 
Javascript :: get element of an array inside another array 
Javascript :: state in constructor javascript 
Javascript :: require a json as a string 
Javascript :: setting up fontawesome with react project 
Javascript :: es6 method definition syntax 
Javascript :: nuxt query params 
Javascript :: javascript file exists check 
Javascript :: javascript tostring method 
Javascript :: select react hook form yup validation 
Javascript :: website design html css javascript 
Javascript :: jquerry in bootstrap 
Javascript :: hover material ui styles 
Javascript :: js loop backwards 
Javascript :: mongoose update push 
Javascript :: npm run js file from command line 
Javascript :: react render component after fetch 
Javascript :: jquery find 
Javascript :: jquery post 
Javascript :: how to get an array from another script in js 
Javascript :: adding cypress to react project using npm 
Javascript :: promise.all vs promise.allsettled 
Javascript :: js create element 
Javascript :: create a loop that runs through each item in an array 
Javascript :: repeat an array multiple times in js 
Javascript :: push json into json 
Javascript :: hash object javascript 
Javascript :: php watermark facile 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =