Currently, I am diving into the world of Grunt and attempting to integrate an Express server into my AngularJS application that was initially created with Yoeman.
I've made adjustments to the following task as shown below:
grunt.registerTask('server', function () {
grunt.log.writeln('Launching web server on port 8080.');
var server = require('./server.js');
server.listen(8080);
});
Here is a snippet from my server.js file:
var express = require('express');
var app = module.exports = express();
app.get('/', function(req, res){
res.send('hello world');
});
When executing the server task
, it generates the output displayed below:
Executing "server" task
Starting web server on port 8080.
Completed without any errors.
Upon navigating to localhost on port 8080, the server appears to be offline. It seems evident that the task terminates. What steps should I take to ensure a basic functioning server? Do I need to include something in the Gruntfile?
Update: Perhaps I should incorporate a 'keepalive' option in my task somehow, though I am uncertain of the process.