require 'server'
const server = require('server')
server.createServer(port)
server.addRoute(method, path, callback)
method: GET / POST path: The URL path callback: Function executed after client hits the route
-
server.addRoute('GET', '/', (request, response) => { response.render('index.html') })
server.addRoute('POST', '/post', (req, res) => { console.log('body >>>', req.body) res.setStatus(200) res.send() })
-
- renders file "views/index.html"
- './views' is the default directory. All your html files should be here for res.render to work
-
- converts 'data' to JSON and puts it in res.body
- NOTE: res.send() is needed to write the data to the socket
res.json("lorem ipsum") res.send()
-
- sets res.statusCode and the appropriate res.statusMessage to the response object