I am going to learn Node.js and right now I was trying to make a small demo project which implements an HTTP REST service. My idea is to divide the APIs (url) by Resources and end up in a structure like the following one:
- user
> index.js
> post.js
> put.js
> delete.js
> functions.js
- person
> index.js
- index.js
So, if you are familiar with ASP.NET Web Api, I am trying to make every module of Node.js a Controller and every web method a single file (.js), in order to have an high maintainability in the future.
Question Right now, my index.js file return the following:
var http = require('http');
var server = http.createServer();
How can I configure a specific "Request Handler" in each file by using this module? At the moment the createServer() method return a server object can use a single server.on('request', function) while I need to handle each request in a different file.
post,put... returnsRouterobject that you can attach to the server.