Apparatus for treating patients with motility disorders applies a modulating signal to the patient's vagus nerve to stimulate or inhibit neural impulses and produce excitatory or inhibitory neurotransmitter release by the vagus nerve according to the specific nature of the motility disorder. The apparatus includes a neurostimulator which can be activated to generate an electrical output signal. The neurostimulator is responsive to the sensing of a selected event having occurred which is indicative of the need for treatment of the motility disorder, and includes an activation element which responds to sensing of that event to activate the neurostimulator, and a lead with an electrode array to apply the electrical output signal as the modulating signal to the patient's vagus nerve. Certain parameters of the output signal are programmable, and the neurostimulator can be calibrated according to the specific patient and the specific motility disorder being treated. One form of sensor detects the impedance of a selected part of the gastrointestinal system to detect the presence of excessive contractions in that part as an indication of hypermotility whether or not food has been consumed by the patient within a preset interval of time, and inadequate contractions in that part as an indication of hypomotility if food was consumed by the patient within a preset interval of time.