NodeJS REST API Application - Structure

71 views
Skip to first unread message

InfantJoseph S

unread,
Aug 4, 2017, 2:13:45 AM8/4/17
to nodejs
Am a newbie here. I want to develop a NodeJS application which serves only to expose REST APIs. My application have nothing to do with View. I used Express generator to generate a project and I removed the views folder. Also I changed the package.json 'start' from 'node bin/www' to 'node app.js'. But it didn't worked.

How can I structure my project so that it will initialise with routes and  my APIs will be exposed.

I got a suggestion to use 'Swagger', but I need to work with .yaml file and didn't want my team to do considering future dependencies. Thanks for the help in advance.

app.js

var express = require('express');
var bodyParser = require('body-parser');
var contoller = require('./domains/apply/controller');

var app = express();
app.use(bodyParser.json());

app.post('/email', (req, res) => {
  console.log(req.body.address);
  res.json({ ok: true });
});

app.listen(4443, () => console.log('Listening on http://localhost:4443/'));



controller.js

app.get('/employee', function(req, res){
  "use strict";
    console.log(" employee ---- "+req);
    res.json({ ok: true });
});

DaneiL

unread,
Aug 7, 2017, 5:56:11 PM8/7/17
to nod...@googlegroups.com
I have a proof of concept project, u can follow to use in your rest api.

there is an express app that only handles json. 

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/99c3bb5e-50cb-4bb4-9060-b2abd4a0d34c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
[]'s
Reply all
Reply to author
Forward
0 new messages