How to use the morgan function in morgan

To help you get started, we’ve selected a few morgan 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 marcells / node-build-monitor / app / app.js View on Github external
import express from 'express';
import http from 'http';
import path from 'path';
import socketio from 'socket.io';
import config from './config';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import errorhandler from 'errorhandler';

let app = express();

app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon(path.join(__dirname, 'public/images/favicon.ico')));
app.use(morgan('combined'));
app.get('/', (req, res) => res.render('index', {
  title: 'Build Monitor'
}));
app.use(express.static(path.join(__dirname, 'public')));

if ('development' === app.get('env')) {
  app.use(errorhandler());
}

// run express
let server = http.createServer(app),
  io = socketio.listen(server);

server.listen(
  app.get('port'), () => console.log(`node-build-monitor is listening on port ${app.get('port')}`));
github freeCodeCamp / chapter / server / index.ts View on Github external
nextjs.nextApp.prepare().then(async () => {
  const port = process.env.PORT || 8000;

  const connection = await initDB;
  await connection.runMigrations();

  app.use(
    morgan(':method :url :status', {
      skip: (req: express.Request) => req.url.startsWith('/_next/'),
    }),
  );
  app.use(express.json());
  app.use(express.static('public'));

  app.use(apiV1);

  app.use(responseErrorHandler);

  app.get('*', (req, res) => {
    nextjs.handle(req, res);
  });

  app.listen(port, () => {
    console.log(`\n\nstarted on port ${port}\n\n`); // tslint:disable-line no-console
github IamMohaiminul / MERNjs / client / app.js View on Github external
import express from 'express';
import path from 'path';
import favicon from 'serve-favicon';
import logger from 'morgan';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';

const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

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')));

// route handlers
app.get('*', function (req, res) {
  res.render('index', { title: 'MERN' });
});

export default app;
github revathskumar / react-server-render / src / app.js View on Github external
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';

import routes from './routes/index';
import users from './routes/users';

const app = express();

// view engine setup
app.set('views', path.join(__dirname, '..', 'views'));
app.set('view engine', 'pug');

app.locals.pretty = true;
// uncomment after placing your favicon in /public
//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.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers
github jhnns / spa-vs-universal / universal / server / index.js View on Github external
import config from "./config";
import api from "./api";
import { isDev } from "./env";

const app = express();
const pathToPublic = path.resolve(process.cwd(), "dist", "public");
const universalApp = require(path.resolve(process.cwd(), "dist", "app", "server")).default;
const expectedReferrers = ["http://" + config.hostname + ":" + config.port];

if (isDev) {
    expectedReferrers.push("http://" + config.hostname + ":" + config.devServerPort);
}

app.server = http.createServer(app);

app.use(morgan("dev"));
app.use(helmet());
// "same-origin" would be the best, but "origin-when-cross-origin" has the best cross-browser support
app.use(helmet.referrerPolicy({ policy: "origin-when-cross-origin" }));
app.use(
    bodyParser.json({
        limit: config.bodyLimit,
    })
);
app.use(
    bodyParser.urlencoded({
        limit: config.bodyLimit,
        extended: true,
    })
);
app.use(session(config.session));
api(app);
github melihkorkmaz / il-ilce-mahalle-geolocation-rest-api / src / index.js View on Github external
import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import routes from './routes';
import mongo from './utils/mongo.helper';
import config from './config';
import loggerMiddleware from './utils/logger.middleware';

const app = express();
const { NODE_ENV } = process.env

if (NODE_ENV !== 'test') {
	mongo.connect(() => console.log('connected'));
	app.use(morgan('tiny'));
}


app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

if(NODE_ENV === "production")
	app.use(loggerMiddleware);

app.get('/', (req, res) => res.send('İl ilçe mahalle rest-api'));

routes(app);


if (NODE_ENV === 'test') {
	module.exports = app;
github happylolonly / events-free-spa / server / middlewares / index.js View on Github external
export default (app, express) => {
  app.use(morgan('combined'));

  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());

  app.use(compression());

  app.use(express.static(path.join(__dirname + '/../static/build'), { index: false }));
};

morgan

HTTP request logger middleware for node.js

MIT
Latest version published 4 years ago

Package Health Score

81 / 100
Full package analysis