For those working with Node.js, you have the option to implement a similar solution by ensuring that you have installed the necessary NPM packages: express
and less
.
const express = require('express');
const less = require('less');
const app = express();
app.get('/generateCSS/:number', function(req, res){
less.render('.class { width: ' + req.params.number + 'px; }', function (e, css) {
res.send(css);
});
});
app.listen(3000);
This script is a basic implementation (without error handling or input validation) which will process requests made to
http://localhost:3000/generateCSS/:number
and display the specified
number
within your LESS code.
# curl http://localhost:3000/generateCSS/6
.class {
width: 6px;
}
You have the flexibility to utilize these parameters in any manner within your LESS templates as needed.