Package Exports
- server
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Server for Node.js
Simple and powerful server that just works so you can focus on your awesome project:
const server = require('server');
// Serve static files from /public on port 3000
server();
// OR serve static files from the root on port 8080
server({ port: 8080, public: './' });
// OR use some simple routes on http://localhost:3000/
const { get, post } = server.router;
server(
get('/', ctx => ctx.res.render('index')),
post('/', ctx => console.log(ctx.req.body))
);
Getting started
After getting Node.js 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:
// Include the server in your file
const server = require('server');
const { get, post } = server.router;
// Initialize the server on port 3000
server(3000,
// Handle requests to the url "/" ( http://localhost: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:
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.
I love using my work and I'm available for contractor work. Freelancing helps maintain server
and my other open source projects up to date! Hire me to do:
- Front-end: Picnic CSS ♦ Paperdocs ♦ Angular Attack ♦ Ruby Rampage ♦ Server JS website
- Full-stack: Makers UPV ♦ Learning vocabulary
- Back-end: Server JS (the library) ♦ Drive DB ♦ Express Data Parser
You can also sponsor the project and your logo will be shown here with ∞ ♥. Open an issue to have an open conversation or contact me directly (email in my website).