{"library":"node-sass-middleware","title":"Node Sass Middleware for Connect/Express","description":"node-sass-middleware is a Connect/Express middleware designed to automatically recompile `.scss` or `.sass` files on demand for web servers. It leverages the `node-sass` library (which in turn uses LibSass) to provide on-the-fly compilation, caching, and debugging capabilities directly within a Node.js web application stack. The package's current stable version is 1.1.0, with its latest patch release (v1.1.0) occurring in 2024. While the package itself sees intermittent updates, its core dependency, `node-sass`, is officially deprecated and no longer actively maintained. This means `node-sass-middleware` is primarily suited for maintaining existing projects rather than new development, where modern Dart Sass solutions are generally preferred. It integrates seamlessly into existing Connect or Express applications, offering a convenient bridge between Sass source files and served CSS.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-sass-middleware"],"cli":null},"imports":["const sassMiddleware = require('node-sass-middleware');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const express = require('express');\nconst sassMiddleware = require('node-sass-middleware');\nconst path = require('path');\nconst app = express();\n\n// IMPORTANT: Place sassMiddleware *before* express.static\napp.use(sassMiddleware({\n    src: path.join(__dirname, 'sass'), // Source directory for .scss/.sass files\n    dest: path.join(__dirname, 'public'), // Destination directory for .css files\n    debug: true, // Output debugging info to console\n    outputStyle: 'compressed', // Minify CSS output\n    prefix: '/styles' // CSS will be served from /styles/your_file.css\n}));\n\n// Serve static files from the 'public' directory, including compiled CSS\napp.use('/styles', express.static(path.join(__dirname, 'public')));\n\n// Example route for demonstration\napp.get('/', (req, res) => {\n  res.send('<!DOCTYPE html><html><head><link rel=\"stylesheet\" href=\"/styles/main.css\"></head><body><h1>Hello from node-sass-middleware!</h1></body></html>');\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n    console.log(`Server listening on port ${PORT}`);\n    console.log(`Open http://localhost:${PORT} in your browser.`);\n    console.log(`Ensure you have a 'sass' directory with 'sass/main.scss' (e.g., body { h1 { color: darkblue; } }) and an empty 'public' directory.`);\n});","lang":"javascript","description":"Demonstrates setting up `node-sass-middleware` with an Express application to compile SASS files on the fly and serve them as static CSS, highlighting the correct middleware order. To run, create a 'sass' directory with a 'main.scss' file (e.g., `body { background-color: lightblue; h1 { color: darkblue; } }`) and an empty 'public' directory in the same location as your script.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}