1.0.3 • Published 5 years ago

@nonpolynomial/lambda-server v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Lambda-Server

Run lambda functions with a http server.

How it works

If you have the following directory structure and files, you can simply import lambda-server and start it. The lambda-server expects to parameters: a directory and a port.

.
├── lambda
│   ├── foo
│   │   └── bar.js
│   └── hello-world.js
└── index.js
$ npm -g i @nonpolynomial/lambda-server

# or

$ yarn add @nonpolynomial/lambda-server
// index.js
const lambda = require('lambda');

const lambdaServer = lambda(`${__dirname}/lambda`, 8080);
// lambda/foo/bar.js
module.exports = (req, res) => {
  res.end(JSON.stringify({ foo: 'bar' }));
};
// lambda/hello-world.js
module.exports = (req, res) => {
  res.end('hello world');
};

Because we started lambda-server with lambda as directory, you get a hello world if you visit http://localhost:8080/hello-world.

The file, that gets loaded, depends on the path you visit.

URL-pathloaded filepath
/foo/barfoo/bar.js
/hello-worldhello-world.js

...or use lambda server with your CLI

npm -g i @nonpolynomial/lambda-server

# or

yarn global add @nonpolynomial/lambda-server
$ lambda ./lambda --port 1337
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago