Server
Simple and powerful server for Node.js:
const server = require('server');
server();
server({ port: 8080, public: './' });
const { get, post } = server.router;
server(
get('/', ctx => ctx.res.render('index')),
post('/', ctx => console.log(ctx.req.body))
);
Getting started
After getting Node ready and npm init
, run this in your project folder to install the server:
npm install server --save
Then you can create a file called app.js
and set the following:
let server = require('server');
let { get, post } = server.router;
server(3000,
get('/', ctx => ctx.res.send('Hello world!'))
);
Execute this in the terminal to get the server started:
node app.js
And finally, open your browser on localhost:3000 and you should see your server answered 'Hello world!'.
Documentation
Everything is documented in detail here:
Full Documentation
You can also download the repository and try the examples by browsing to them and node app.js
inside each of them in /examples
.
License
Licensed under the MIT License. See LICENSE for the full license.
Author
This package was created by Francisco Presencia but hopefully developed and maintained by many others. See the the list of contributors here.
Hire me
I love using my work in real life and I'm available for contractor work. My freelancing helps keep server
and my other open source projects up to date! Hire me to do:
Find my email in my website.