How to use the body-parser.urlencoded function in body-parser

To help you get started, we’ve selected a few body-parser 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 Netflix / falcor / test / integration / express.spec.js View on Github external
beforeEach(function(done) {
        var app = express();
        app.use(bodyParser.urlencoded({ extended: false }));

        // Simple middleware to handle get/post
        app.use('/model.json', FalcorServer.dataSourceRoute(function(req, res) {
            return new FalcorRouter([
                {
                    // match a request for the key "greeting"
                    route: "greeting",
                    // respond with a PathValue with the value of "Hello World."
                    get: function() {
                        return {path:["greeting"], value: "Hello World"};
                    }
                }
            ]);
        }));

        server = app.listen(60001, done);
github sendgrid / sendgrid-nodejs / packages / subscription-widget / index.js View on Github external
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const router = require('./server/router');

// App setup
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
router(app);

// Server setup
const port = process.env.PORT || 3090;
const server = http.createServer(app);
server.listen(port);
console.log('Server listening on:', port);
github build-js-app / build-app / templates / server / ts / src / server.ts View on Github external
function initExpress() {
    if (config.isDevLocal) app.use(morgan('dev')); //log requests

    app.use(bodyParser.json()); // get information from html forms
    app.use(bodyParser.urlencoded({extended: true}));

    app.use('/static', express.static(pathHelper.getClientRelative('/static')));

    app.use(cors());
}
github patrocinio / microbank / src / log-viewer / 1.0 / server.js View on Github external
// server.js

// BASE SETUP
// =============================================================================

// call the packages we need
var express    = require('express');        // call express
var app        = express();                 // define our app using express
var bodyParser = require('body-parser');
var viewer     = require('./logViewer');
var chaos      = require('./chaos_router/chaos_router.js');

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || 80;        // set our port

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router();              // get an instance of the express Router

app.use (chaos);

router.get('/', function(req, res) {
	res.send("I'm healthy")
})

// more routes for our API will happen here
github codingfriend1 / meanbase / server / config / express.js View on Github external
module.exports = function(app) {
  var env = app.get('env');

  app.set('views', config.root + '/server/views');
  app.set('view engine', 'jade');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  // Persist sessions with mongoStore
  // We need to enable sessions for passport twitter because its an oauth 1.0 strategy
  app.use(session({
    secret: config.secrets.session,
    resave: true,
    saveUninitialized: true,
    store: new mongoStore({ mongoose_connection: mongoose.connection })
  }));

  if ('production' === env) {
    // app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
github iquidus / explorer / app.js View on Github external
getsupply - Returns the current money supply.
    getmaxmoney - Returns the maximum possible money supply.
  */
  bitcoinapi.setAccess('only', ['getinfo', 'getstakinginfo', 'getnetworkhashps', 'getdifficulty', 'getconnectioncount',
    'getblockcount', 'getblockhash', 'getblock', 'getrawtransaction','getmaxmoney', 'getvote',
    'getmaxvote', 'getphase', 'getreward', 'getnextrewardestimate', 'getnextrewardwhenstr',
    'getnextrewardwhensec', 'getsupply', 'gettxoutsetinfo']);
}
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(favicon(path.join(__dirname, settings.favicon)));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// routes
app.use('/api', bitcoinapi.app);
app.use('/', routes);
app.use('/ext/getmoneysupply', function(req,res){
  lib.get_supply(function(supply){
    res.send(' '+supply);
  });
});

app.use('/ext/getaddress/:hash', function(req,res){
  db.get_address(req.params.hash, function(address){
    if (address) {
      var a_ext = {
github pravj / x3030 / app.js View on Github external
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes');

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.set('port', process.env.PORT || 3000);

app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', routes.index);

http.createServer(app).listen(app.get('port'), function(){
  console.log('x3030 server running on port ' + app.get('port'));
});
github notadd / next / packages / core / notadd-application.js View on Github external
setupParserMiddlewares() {
        const parserMiddlewares = {
            jsonParser: bodyParser.json(),
            urlencodedParser: bodyParser.urlencoded({ extended: true }),
        };
        Object.keys(parserMiddlewares)
            .filter(parser => !this.isMiddlewareApplied(this.express, parser))
            .forEach(parserKey => this.express.use(parserMiddlewares[parserKey]));
    }
    isMiddlewareApplied(app, name) {
github ccns / CCNS-Radio / route / search.js View on Github external
constructor (api_key) {
    this.router = express.Router()
    this.api_key = api_key
    this.base_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&key=' + this.api_key

    this.router.use(bodyParser.urlencoded({ extended: false }))
    this.router.use(bodyParser.json())

    var self = this

    this.router.post('/', function (req, res) {
      var q = req.body.q
      var pageToken = req.body.pageToken

      self.search(q, pageToken).then(function (data) {
        res.json(data)
      }).catch(function (err) {
        res.send('Failed')
      })
    })
  }
github howdyai / botkit / lib / Tropo.js View on Github external
controller.setupWebserver = function(port, cb) {

        if (!port) {
            throw new Error('Cannot start webserver without a port');
        }

        var static_dir =  __dirname + '/public';

        if (controller.config && controller.config.webserver && controller.config.webserver.static_dir)
            static_dir = controller.config.webserver.static_dir;

        controller.config.port = port;

        controller.webserver = express();
        controller.webserver.use(bodyParser.json());
        controller.webserver.use(bodyParser.urlencoded({ extended: true }));
        controller.webserver.use(express.static(static_dir));

        var server = controller.webserver.listen(
            controller.config.port,
            controller.config.hostname,
            function() {
                controller.log('** Starting webserver on port ' +
                    controller.config.port);
                if (cb) { cb(null, controller.webserver); }
            });

        return controller;

    };

body-parser

Node.js body parsing middleware

MIT
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis