Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
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

how to start a node server

// app.js

const http = require('http');
const fs = require('fs')

// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
    // Set a response type of plain text for the response
    res.writeHead(200, {'Content-Type': 'text/html'});
    fs.createReadStream('index.html').pipe(res)
});

// Start the server on port 3000
app.listen(3000, '127.0.0.1');
console.log('Node server running on port 3000');
Comment

create node server

const http = require('http')
const fs = require('fs')
const port = 3000

const server = http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'})
    fs.readFile('index.html', function(error, data) {
        if (error) {
            res.writeHead(404)
            res.write('Error: File Not Found')
        } else {
            res.write(data)
        }
        res.end()
    })
})

server.listen(port, function(error) {
    if (error) {
        console.log('Something went wrong', error)
    } else {
        console.log('Server is listening on port ' + port)
    }
})
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

how to start node server

// app.js

const http = require('http');

// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
    // Set a response type of plain text for the response
    res.writeHead(200, {'Content-Type': 'text/plain'});

    // Send back a response and end the connection
    res.end('Hello World!
');
});

// Start the server on port 3000
app.listen(3000, '127.0.0.1');
console.log('Node server running on port 3000');
Comment

start node.js server

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

simple nodejs server

// One Line ES6
require('http').createServer((req, res) => res.end(`You're in: ${req.url}`)).listen(8080, err => err ? console.log : console.log(`Listening on port 8080`))
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 :: jquery class selector 
Javascript :: check-if-a-javascript-string-is-a-url 
Javascript :: sequelize.fn 
Javascript :: react toastify is not working 
Javascript :: update map value javascript 
Javascript :: jquery json to table 
Javascript :: react native margin vs padding 
Javascript :: ng-pick-datetime 
Javascript :: javascript for loop array of objects 
Javascript :: how to get keys from request headers in express 
Javascript :: array with unique values javascript 
Javascript :: dm message collector discordjs 
Javascript :: how to setup icomoon in react js 
Javascript :: react history listen get previous location 
Javascript :: react hide element 
Javascript :: Key Type 
Javascript :: how to use empty href link in reactjs 
Javascript :: javascript change input value jquery 
Javascript :: js event on change focus 
Javascript :: passport jwt npm 
Javascript :: javascript add to object 
Javascript :: how to add element to an object 
Javascript :: how to pass basic auth for api in angular 11 
Javascript :: This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native. 
Javascript :: mongo connect npm 
Javascript :: v-for only getting one first value vuejs 
Javascript :: angular ng-click toggle class 
Javascript :: sweet alert angular 
Javascript :: indexof javascript duplicate arrays 
Javascript :: js nuxt read/set cookie 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =