David Yuan David Yuan - 12 days ago 5x
AngularJS Question

How do I pass in parameters to the express.js server side routing for a MEAN.js package.

I am a beginner working on a project structured by mean.js. I am still trying to figure out how the whole project struct works and I am a little stuck.

Currently, I have two crud modules. A project module and an application module. Users should be able to apply to projects. Under a certain project, I should be able to view all the applications and then accept/reject them.

I added a custom method onto the angular $resource

function ProjectApplicationsService($resource) {
return $resource('api/projects/:projectId/applications', { projectId: '@_id' }, {
accept: {
method: 'PUT'
reject: {
method: 'PUT'


Once I click a button corresponding to a certain application, it will trigger this function and pass in the application ID as a parameter.

function acceptApp(applicationID){
vm.application._id = vm.project._id;
vm.application.app_id = applicationID;
vm.application.$accept(successCallback, errorCallback);
function successCallback(res) {

function errorCallback(res) {
vm.error = res.data.message;

This should make an API call to express and here is the routing for that

.get(users.requiresLogin, projects.hasAuthorization, projects.getApplications)
.put(users.requiresLogin, projects.hasAuthorization, projects.updateApplication)
.delete(users.requiresLogin, projects.hasAuthorization, projects.deleteApplication);

Essentially, I want to end up calling updateApplication but how do I get the application ID within this method?


Assuming you're going to upload something to the server which will trigger your put route - which contains the function you want to call.

You need to structure your handles like so:

function(request,response,next){ // usually abbreviated to `req,res`
    next(); // move onto the next function;

The parameters are easy to remember by, request comes before response, and then next - You only need next when you want to move onto another handler.

If you don't call next() the route will stop - you'll probably want to call next once authorization succeeds.

data is held in the requests body, so you can access it using request.body

Note: remember to respond to your user - with something like res.send("success"), or they'll time out