Socket
Book a DemoInstallSign in
Socket

server-1min

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-1min

Launch node server in 1 minute.

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

1 Minute Server

Launch node server in 1 minute.

Features

  • No more complex server code.
  • Only need to define routing rules.
  • Support NPX

Usage

Start server with custom routing rules

npx server-1min -f $(pwd)/routes.js

Start server with specific port

npx server-1min -p 8080

Samples

Web Server

const path = require('path');
const express = require('express');

module.exports = [{
  method: 'USE',
  path: '/static',
  callbacks: [
    express.static(path.resolve(__dirname, 'public/static')),
  ],
}, {
  method: 'GET',
  path: '/',
  callbacks: [
    express.static(path.resolve(__dirname, 'public')),
  ],
}];

Webhook inspector

const util = require('util');
const bodyParser = require('body-parser');
const jsonParser = bodyParser.json();

module.exports = [{
  method: 'POST',
  path: '/webhook',
  callbacks: [
    jsonParser,
    (req, res, next) => {
      res.header('Access-Control-Allow-Origin', '*');
      res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
      next();
    },
    (req, res) => {
      console.log(util.inspect(req.body, false, null, true));
      res.status(200).send(req.body);
    },
  ],
}];

Single file upload

const path = require('path');
const fileUpload = require('express-fileupload');

module.exports = [{
  method: 'POST',
  path: '/upload',
  callbacks: [
    fileUpload(),
    (req, res, next) => {
      res.header('Access-Control-Allow-Origin', '*');
      res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
      next();
    },
    (req, res) => {
      if (!req.files) {
        return res.status(400).send('No files were uploaded.');
      }

      const { file } = req.files;

      file.mv(path.resolve(__dirname, file.name), (err) => {
        if (err)
          return res.status(500).send(err);

        res.send('File uploaded!');
      });
    },
  ],
}];

FAQs

Package last updated on 27 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.