Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

express js basic example

//to run : node filename.js
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}`))

//visit localhost:3000
// assuming you have done 1) npm init 2) npm install express
Comment

express js sample project

var express=require('express');
var app=express();

app.get('/',function(req,res){
	res.send("Hello World!");
});

var server=app.listen(3000,function() {});
Comment

express example

const http = require('http');
const app = require('./app');

const normalizePort = val => {
  const port = parseInt(val, 10);

  if (isNaN(port)) {
    return val;
  }
  if (port >= 0) {
    return port;
  }
  return false;
};
const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

const errorHandler = error => {
  if (error.syscall !== 'listen') {
    throw error;
  }
  const address = server.address();
  const bind = typeof address === 'string' ? 'pipe ' + address : 'port: ' + port;
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges.');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use.');
      process.exit(1);
      break;
    default:
      throw error;
  }
};

const server = http.createServer(app);

server.on('error', errorHandler);
server.on('listening', () => {
  const address = server.address();
  const bind = typeof address === 'string' ? 'pipe ' + address : 'port ' + port;
  console.log('Listening on ' + bind);
});

server.listen(port);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to print to console javascript 
Javascript :: npm ERR! errno ECONNRESET 
Javascript :: document ready without jquery 
Javascript :: get distance of element from top of page javascript 
Javascript :: get ng content element angular 2 
Javascript :: datatable processing 
Javascript :: generate random string in javascript 
Javascript :: remove same occurances in two different arrays js 
Javascript :: react or vue 
Javascript :: how to get the extension from filename using javascript 
Javascript :: get text in select jquery 
Javascript :: multer save file with extension 
Javascript :: codewars js Find the first non-consecutive number 
Javascript :: remove attribute javascript 
Javascript :: how to convert timestamp to date in react native 
Javascript :: Writing files in Node.js 
Javascript :: image border shadow react native 
Javascript :: javascript loop thrown object 
Javascript :: loop json object android java 
Javascript :: float to string javascript 
Javascript :: validate json file programmatically in python 
Javascript :: javascript set div height 
Javascript :: jquery radio button checked event 
Javascript :: check solidity version in current project folder truffle 
Javascript :: NotYetImplemented ng2-chart angular 2 
Javascript :: iso string to timestamp javascript 
Javascript :: angular input date binding on variable update 
Javascript :: Required a safe HTML, got a ResourceURL 
Javascript :: Error: open failed: EACCES (Permission denied) react native 
Javascript :: moment between exclusivity 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =