1.0.0 • Published 6 years ago
http-server-lib v1.0.0
webServer-node
An HTTP server library written using Node.js net module
Installation
Before installing the library, download and install Node.js and npm Once Node.js and npm is successfully installed, install http-server-lib from npm by using npm install command
$ npm install http-server-lib
Running this will create a node modules directory in your current directory (if one doesn't exist yet) and download the package in that directory.
Getting Started
Creating a server instance
const server = require('./server/tcp-server')
server.startServer(port)
Adding routes
const server = require('./server/tcp-server')
server.startServer(port)
server.addRoutes('GET', '/', (request, response) => {
response.body = 'Hello World!'
response.send()
})
Using middlewares
const server = require('./server/tcp-server')
const logger = require('./middlewares/logger')
const bodyParser = require('./middlewares/bodyParser')
server.startServer(port)
server.addHandler(bodyParser.parseUrlEncodedBody)
server.addHandler(logger)
server.addRoutes('POST', '/data.html', (req, res) => {
res.body = req.body['fieldName']
res.setHeaders()
res.setContentType('/data.html')
res.send()
})
Note: Middlewares are processed in the order that they are added
Features
Static file handling
Session handling
Body parsing with support for multipart/form-data and multipart/mixed type requests
Look here for an example app that uses this library
License
1.0.0
6 years ago