How to use http - 10 common examples

To help you get started, we’ve selected a few http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwadhams / json-logic-js / tests / tests.js View on Github external
var download = function(url, dest, cb) {
  var file = fs.createWriteStream(dest);
  http.get(url, function(response) {
    response.pipe(file);
    file.on("finish", function() {
      file.close(cb);  // close() is async, call cb after close completes.
    });
  }).on("error", function(err) { // Handle errors
    fs.unlink(dest); // Delete the file async. (But we don't check the result)
    if (cb) cb(err.message);
  });
};
github Alexiuce / StatusBarDemoApp / Web / node入门 / 26-server.js View on Github external
// 导入node.js http模块
const http = require('http');
// 创建http server 对象;
const server = http.createServer((req,res)=>{
    console.log("server start.....");
});
// 启动server 监听端口;
server.listen(8080);
github surmon-china / simple-netease-cloud-music / src / netease.js View on Github external
return new Promise((resolve, reject) => {
            const req = http.request(options, res => {
                res.setEncoding('utf8')
                this[onResponse](res, resolve, reject)
            })

            req.on('error', err => {
                console.error(`problem with request: ${err.message}`)
            })

            // write data to request body
            if (form) {
                req.write(form)
            }
            req.end()
        })
    }
github AquiGorka / puppets / src / server / index.js View on Github external
"use strict";

var express = require('express');
var server = express();
var http = require('http').Server(server);
var PORT = 8000;

// socket server
http.listen(PORT);
// http server
server.use(express.static(__dirname + '/../../'));
//
console.log('Server ON : *:' + PORT);
github rtc-io / rtc-switchboard / examples / express.js View on Github external
var express = require('express');
var app = express();
var server = require('http').Server(app);
var port = process.env.PORT || 3000;

// create the switchboard
var switchboard = require('..')(server);

server.listen(port, function(err) {
  if (err) {
    return;
  }

  console.log('server listening on port: ' + port);
});
github TobiasWalle / rush / src / api / server / api-server.ts View on Github external
constructor(
    public host: string,
    public port: number
  ) {
    // Setup app
    const app = express();
    this.server = http.createServer(app);
    enableDestroy(this.server);

    // Setup main router
    this.router = new ApiRouter();
    app.use((req, res, next) => {
      this.router.route(req, res, next);
    });
  }
github steptools / NC.js / src / server / api_server.js View on Github external
_setSocket(){
    // Socket server
    this.server = http.Server(this.express);
    this.ioServer = io(this.server, {});
    this.ioServer.use(ioSession(this.session));
    this.ioServer.on('connection', function (socket) {
      socket.on('disconnect', function () { });
    });
  };
github Producters / express-crawler-snapshots / tests / testapp / server.js View on Github external
var getApp = require('./app'),
    http = require('http'),
    middleware = require('../../index');

var app =  getApp(middleware({
    maxInstances: 1
}));
server = http.Server(app);
server.listen(3000);
console.log('server started at http://localhost:3000/');
github collective-soundworks / soundworks / server / ioServer.es6.js View on Github external
init(app) {
    var server = http.createServer(app);

    server.listen(app.get('port'), function() {
      console.log('Server listening on port', app.get('port'));
    });

    this.server = server;

    if (server)
      this.io = new IO(server);
  }
}
github arithmetric / lambda-stash / handlers / shipHttp.js View on Github external
return new Promise(function(resolve, reject) {
    var http = require('http');
    var url = require('url');
    var options = url.parse(config.http.url);
    options.method = 'POST';
    var req = http.request(options, function(res) {
      console.log('Received HTTP response status code: ' + res.statusCode);
      resolve(config);
    });
    req.on('error', function(err) {
      reject('An error occurred when making an HTTP request: ' + err);
    });
    var keyData = config.http.keyData || 'data';
    req.write(config[keyData]);
    req.end();
  });
};

http

security holding package

Unknown
Latest version published 5 years ago

Package Health Score

47 / 100
Full package analysis