How to use the express function in express

To help you get started, we’ve selected a few express 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 leebenson / graphql-with-sequelize / server.js View on Github external
import Express from 'express';
import GraphHTTP from 'express-graphql';
import Schema from './schema';

// Config
const APP_PORT = 3000;

// Start
const app = Express();

// GraphQL
app.use('/graphql', GraphHTTP({
  schema: Schema,
  pretty: true,
  graphiql: true
}));

app.listen(APP_PORT, ()=> {
  console.log(`App listening on port ${APP_PORT}`);
});
github SUI-Components / sui / packages / sui-ssr / server / index.js View on Github external
import TYPES from '../hooks-types'
import basicAuth from 'express-basic-auth'
import path from 'path'
import fs from 'fs'
import jsYaml from 'js-yaml'
import parseDomain from 'parse-domain'
import compression from 'compression'
import ssrConf from './config'
import {
  isMultiSite,
  siteFromReq,
  useStaticsByHost,
  readHtmlTemplate
} from './utils'

const app = express()

app.set('x-powered-by', false)

// Read public env vars from public-env.yml file and make them available for
// middlewares by adding them to app.locals
try {
  const publicEnvFile = fs.readFileSync(
    path.join(process.cwd(), 'public-env.yml'),
    'utf8'
  )
  app.locals.publicEnvConfig = jsYaml.safeLoad(publicEnvFile)
} catch (err) {
  app.locals.publicEnvConfig = {}
}

// Read early-flush config.
github jaredpalmer / razzle-react-vue-elm-php-lol / src / server.js View on Github external
import Vue from 'vue';
const renderer = require('vue-server-renderer').createRenderer();
import { createVueApp } from './Main.vue.js';

// REACT
import React from 'react';
import { StaticRouter } from 'react-router-dom';
import { renderToString } from 'react-dom/server';
import App from './App.react';

// ELM
import elmStaticHtml from 'elm-static-html-lib';
require('./Main');

const assets = require(process.env.RAZZLE_ASSETS_MANIFEST);
const server = express();

server
  .disable('x-powered-by')
  .use(express.static(process.env.RAZZLE_PUBLIC_DIR))
  .get('*', async (req, res) => {
    // VUE
    const context = { url: req.url };
    const { app } = createVueApp(context);
    const vueMarkup = await renderer.renderToString(app);

    // REACT
    const reactMarkup = renderToString(
      
        
      
    );
github philopian / AppSeed / DEPLOY / nodejs / server / index.js View on Github external
import path from 'path';
import chalk from 'chalk';
import express from 'express';
import compression from 'compression';
import bodyParser from 'body-parser';

const config = require('../config');
const apiRoute = require('./api');
const jwtAuth = require('./jwt-auth');
const db = require('./db');

const app = express();

/******** Middleware *************************************/
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  res.set('X-Powered-By', 'AppSeed');
  next();
});


app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json


/******** API Calls	**************************************/
github devconcept / multer-gridfs-storage / test / storage-constructor.spec.js View on Github external
function prepareTest(t, opts) {
	const app = express();
	const storage = new GridFsStorage(opts);
	const upload = multer({storage});
	t.context.storage = storage;
	t.context.upload = upload;
	t.context.app = app;
}
github FormidableLabs / yesno / test / test-server.ts View on Github external
export function start(port: number = PORT): Promise {
  let requestCount: number = 0;
  const app = express();
  app.use(jsonParser());

  app.use((req, res, next) => {
    requestCount++;
    next();
  });

  app.get('/get', ({ headers }: express.Request, res: express.Response) => {
    debug('Received GET request');
    res.status(headers['x-status-code'] ? parseInt(headers['x-status-code'] as string, 10) : 200);
    res.setHeader('x-test-server-header', 'foo');
    res.send({ headers, method: 'GET', path: '/get' });
  });

  app.post('/post', ({ headers, body }: express.Request, res: express.Response) => {
    debug('Received POST request');
github onlanta / kanban / src / Application.ts View on Github external
protected runWebServer() {
        this.initCron()
        this.http = Express()
        this.http.use('/', Express.static('vue/dist'))
        this.http.use((req, res, next) => {
            if (req.url.indexOf('/api') === -1) {
                res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate')
                res.header('Expires', '-1')
                res.header('Pragma', 'no-cache')
                return res.send(fs.readFileSync('vue/dist/index.html').toString())
            }
            next()
        })
        this.http.use(Express.urlencoded())
        this.http.use(Express.json())
        this.http.listen(this.config.listen, () => console.log(`Listening on port ${this.config.listen}`))

        this.initializeControllers()
    }
github Abdizriel / nodejs-microservice-starter / server / index.js View on Github external
* @description Routes config class
 * @param Routes
 */
import Routes from './config/routes.conf.js';

/**
 * @description IApplication config class
 * @param Routes
 */
import ApplicationConfig from './config/app.conf.js';

/**
 * @description Create application with Express Framework
 * @param app
 */
const app = express();

/**
 * @description Create application server
 * @param server
 */
const server = http.createServer(app);

/**
 * @description Configure Database
 */
DBConfig.init();

/**
 * @description Configure Application
 */
ApplicationConfig.init(app);
github hanford / trends / api / index.tsx View on Github external
import { ApolloServer } from "apollo-server-express";
import express from "express";
import cors from "cors";

import schema from "./graphql";
import { formatParams, getRepos } from "./common";

const port = parseInt(process.env.PORT || "2999", 10) || 2999;

const server = new ApolloServer({ schema, introspection: true });
const app = express();

app.use(cors());
server.applyMiddleware({ app, path: "/api/graphql", cors: true });

app.get("/api/repos", async (req, res) => {
  const { language, time = 7 } = req.query;
  const { params } = formatParams(language, time);

  const repos = await getRepos(params);

  return res.send({ items: repos });
});

app.listen(port, (err: Error) => {
  if (err) throw err;