Below you will find a custom route template that you can easily modify to fit in your project.

This include all the CRUD(Create, Read, Update, and Delete) operations.

Step 1

Just copy and paste the code below and save it as a javascript as "my-custom-route.js" 

/*
	Your Custom Route -> CRUD 

	C = Create
	R = Read/Get
	U = Update 
	D = Delete

	This will add data to options table
*/



//--->get data - start
app.get('/api/custom/options', function(req, res, next) 
{ 
	var site_url = func.DomainURL(req).cur_path
 	func.log('GET-> '+ site_url )
 
	var option_name 	= _.escape(req.query.option_name) 

	if(_.size(option_name) < 1) 
	{
		res.json( {status:'error', msg:'missing option name  in api call'})
		return false
	}

	//get the option from database
	npdb.collection('np_options')
	.find({option_name: option_name, autoload:'no'},  {'option_value': true, '_id':false})
	.toArray(function (err,  data)
	{
		if(_.size(data) < 1) 
		{
			res.json( {status:'error', msg:'invalid option name'})
			return false
		}			
		res.json( {status:'success', msg:'found option data', option_value: data[0].option_value})
	})
})
//--->get data - end


//--->create new data - start
app.put('/api/custom/options', function(req, res, next) 
{ 
 
	//your parameters from ajax call
	var option_name 	= _.escape(req.query.option_name) 
	var option_value 	= _.escape(req.query.option_value) 



	if(_.size(option_name) < 1) 
	{
		res.json( {status:'error', msg:'missing option_name in api call'})
		return false
	}

	var site_url = func.DomainURL(req).cur_path 

	//log api call	
	func.log('PUT-> '+ site_url ) 

	//do you put request stuff below

	//create option object
	var np_options =
	{
		option_id: +moment(),	
		option_name: option_name,	
		option_value: option_value,
		autoload:'no',
		rec_dttm: moment().format("YYYY-MM-DD h:mm:ss a"),
		rec_dttm_unix: +moment(),
	}

	//check to see if option name exist
	npdb.collection('np_options').find({option_name:option_name  }).toArray(function (err,  data)
	{
		if(_.size(data) <1)
		{				
			//didn't any option name...so insert it now... 
			npdb.collection('np_options').insert(np_options)
			res.json( {status:'success', msg:'aded new option data',  })				
			return false
		}			
		else if(_.size(data) > 0)
		{
			res.json( {status:'error',msg:'option name already in db'  }) 
			return false
		}
	}) 	 

});
//--->create new data - end






//--->update data - start
app.post('/api/custom/options', function(req, res, next) 
{ 
	//your parameters from ajax call
	var option_name 	= _.escape(req.query.option_name) 
	var option_value 	= _.escape(req.query.option_value) 

	if(_.size(option_name) < 1) 
	{
		res.json( {status:'error', msg:'missing option_name in api call'})
		return false
	}

	var site_url = func.DomainURL(req).cur_path 

	//log api call	
	func.log('POST -> '+ site_url ) 


	//check to see if option name exist
	npdb.collection('np_options').find({option_name:option_name  }).toArray(function (err,  data)
	{
		if(_.size(data) <1)
		{				
			//didn't any option name..	
			res.json( {status:'error', msg:'no option name found',  })				
			return false
		}			
		else if(_.size(data) > 0)
		{
			//update option data
			npdb.collection('np_options')
			.updateOne( {option_name: option_name}, { $set: {option_value:option_value} },function (err, result)
			{
				if (err) throw err;					 
				
				res.json( {status:'success', msg:'updated option value',  })
				return false
			})

			return false
		}
	}) 
	

});
//--->update data - end



//--->delete data - start
app.delete('/api/custom/options', function(req, res, next) 
{ 
	//your parameters from ajax call
	var option_name 	= _.escape(req.query.option_name)

	if(_.size(option_name) < 1) 
	{
		res.json( {status:'error', msg:'missing option_name in api call'})
		return false
	}

	var site_url = func.DomainURL(req).cur_path 

	//log api call	
	func.log('DELETE -> '+ site_url ) 


	//check to see if option name exist
	npdb.collection('np_options').find({option_name:option_name  }).toArray(function (err,  data)
	{
		if(_.size(data) <1)
		{				
			//didn't any option name...so insert it now... 		
			res.json( {status:'error', msg:'no option name found',  })				
			return false
		}			
		else if(_.size(data) > 0)
		{
			//delete only first matching option name
			npdb.collection('np_options').deleteOne( {option_name:option_name  });

			//delete all option names 
			//npdb.collection('np_options').deleteMany( {option_name:option_name  });
			
			res.json( {status:'success', msg:'deleted option',  })
		}
	}) 

});
//--->delete data - end

Step 2

From the root folder open up "routes_custom" folder and put the "my-custom-route.js" file in there.

Step 3

Open up "app.js" file from the root folder and require this file name(my-custom-route.js) under

"//--->custom routes > start"

require(__dirname+'/routes_custom/my-custom-route.js'); 

Step 4

Call your custom NodePress JS route or rest api in jQuery:

$.ajax({
  method: "PUT", //POST/PUT/GET/DELETE
  url: "http://mysite.com//api/custom/options", //mysite.com//api/custom/options
  data: { option_name: "John", option_value: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  })

You can use jQuery ajax function to do your CRUD operation.