
π§ Grunt Express Server updated with additional options v2025.4.119
π Bugs are evidentβ’ - MATRIXοΈ
π§ This project is under active development!
π’ We welcome your feedback and contributions.
NodeJS LTS is supported
π οΈ Built on NodeJs version
v22.13.1
π Description
Simple grunt task for running an Express server that works great with LiveReload + Watch/Regarde.
It works with the latest Node and some additional options.
Changelog
readme
Getting Started
This plugin requires Grunt >=1.0.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-p3x-express --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-p3x-express');
The express
task
Setup
In your project's Gruntfile, you can create one or multiple servers:
grunt.initConfig({
express: {
options: {
},
dev: {
options: {
script: 'path/to/dev/server.js'
}
},
prod: {
options: {
script: 'path/to/prod/server.js',
node_env: 'production',
env: {
'NODE_MODE': 'cluster'
}
}
},
test: {
options: {
script: 'path/to/test/server.js'
}
}
}
});
You can override the default options
either in the root of the express
config
or within each individual server task.
Default options
express: {
options: {
cmd: process.argv[0],
opts: [ ],
args: [ ],
background: true,
fallback: function() {},
port: 3000,
node_env: undefined,
env: {},
harmony: false,
delay: 0,
output: ".+",
debug: false,
breakOnFirstLine: false,
logs: undefined
}
}
Usage
By default, unless delay
or output
has been customized,
the server is considered "running" once any output is logged to the console,
upon which control is passed back to grunt.
Typically, this is:
Express server listening on port 3000
If your server doesn't log anything, the express task will never finish and none of the following tasks, after it, will be executed. For example - if you have a development task like this one:
grunt.registerTask('rebuild', ['clean', 'browserify:scripts', 'stylus', 'copy:images']);
grunt.registerTask('dev', ['rebuild', 'express', 'watch']);
If you run the dev task and your server doesn't log anything, 'watch' will never be started.
This can easily be avoided, if you log something, when server is created like that:
var server = http.createServer( app ).listen( PORT, function() {
console.log('Express server listening on port ' + PORT);
} );
If you log output before the server is running, either set delay
or output
to indicate
when the server has officially started.
Starting the server
If you have a server defined named dev
, you can start the server by running express:dev
. The server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops.
Stopping the server
Similarly, if you start the dev
server with express:dev
, you can stop the server
with express:dev:stop
.
grunt.initConfig({
watch: {
express: {
files: [ '**/*.js' ],
tasks: [ 'express:dev' ],
options: {
spawn: false
}
}
}
});
grunt.registerTask('server', [ 'express:dev', 'watch' ])
Important: Note that the spawn: false
options only need be applied to the watch target regarding the express task.
You may have other watch targets that use spawn: true
, which is useful, for example, to reload CSS and not LESS changes.
watch: {
options: {
livereload: true
},
express: {
files: [ '**/*.js' ],
tasks: [ 'express:dev' ],
options: {
spawn: false,
env: {
'NODE_MODE': 'cluster'
}
}
},
less: {
files: ["public/**/*.less"],
tasks: ["less"],
options: {
livereload: false
}
},
public: {
files: ["public/**/*.css", "public/**/*.js"]
}
}
Release History
Old version
https://github.com/ericclemmons/grunt-express-server
π Quick and Affordable Web Development Services
If you want to quickly and affordably develop your next digital project, visit corifeus.eu for expert solutions tailored to your needs.
π Powerful Online Networking Tool
Discover the powerful and free online networking tool at network.corifeus.com.
π Free
Designed for professionals and enthusiasts, this tool provides essential features for network analysis, troubleshooting, and management.
Additionally, it offers tools for:
- π‘ Monitoring TCP, HTTP, and Ping to ensure optimal network performance and reliability.
- π Status page management to track uptime, performance, and incidents in real time with customizable dashboards.
All these features are completely free to use.
β€οΈ Support Our Open-Source Project
If you appreciate our work, consider β starring this repository or π° making a donation to support server maintenance and ongoing development. Your support means the world to usβthank you!
π About My Domains
All my domains, including patrikx3.com, corifeus.eu, and corifeus.com, are developed in my spare time. While you may encounter minor errors, the sites are generally stable and fully functional.
π Versioning Policy
Version Structure: We follow a Major.Minor.Patch versioning scheme:
- Major: π
Corresponds to the current year.
- Minor: π Set as 4 for releases from January to June, and 10 for July to December.
- Patch: π§ Incremental, updated with each build.
π¨ Important Changes: Any breaking changes are prominently noted in the readme to keep you informed.
GRUNT-P3X-EXPRESS Build v2025.4.119
