Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-sass

Package Overview
Dependencies
Maintainers
7
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sass

Wrapper around libsass

  • 4.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-33.16%
Maintainers
7
Weekly downloads
 
Created

What is node-sass?

The node-sass npm package is a library that allows you to natively compile .scss files to CSS at incredible speed and automatically via a connect middleware. It provides a binding for Node.js to the Sass engine, which is written in C++ and allows for the translation of SCSS or SASS syntax into standard CSS that browsers can understand.

What are node-sass's main functionalities?

Compiling SCSS to CSS

This feature allows you to compile .scss files into .css files. The 'render' method takes an options object and a callback function. The options object specifies the input and output paths for the SCSS and CSS files, respectively. The callback is invoked after the compilation process, and you can handle the result or error accordingly.

const sass = require('node-sass');
sass.render({
  file: 'path/to/input.scss',
  outFile: 'path/to/output.css'
}, function(error, result) { // Node-style callback from v3.0.0 onwards
  if(!error){
    // No errors during the compilation, write this result on the disk
    fs.writeFile('path/to/output.css', result.css, function(err){
      if(!err){
        //file written on disk
      }
    });
  }
});

Watching files or directories

This feature allows you to watch .scss files or directories for changes and automatically recompile them to CSS when a change is detected. The example uses 'chokidar', an external library for watching files, to listen for changes on the specified SCSS file and then uses node-sass to compile the file to CSS.

const sass = require('node-sass');
const chokidar = require('chokidar');

chokidar.watch('path/to/input.scss').on('change', () => {
  sass.render({
    file: 'path/to/input.scss',
    outFile: 'path/to/output.css'
  }, function(error, result) {
    if (!error) {
      fs.writeFile('path/to/output.css', result.css, function(err){
        if(!err){
          console.log('SCSS file updated.');
        }
      });
    }
  });
});

Command Line Interface (CLI) usage

node-sass provides a CLI for compiling SCSS files to CSS directly from the command line. In this example, the '--output-style' option is used to specify the CSS output format (compressed in this case), '-o' is used to define the output directory for the compiled CSS, and the last argument is the input directory containing the SCSS files.

node-sass --output-style compressed -o dist/css src/scss

Other packages similar to node-sass

Keywords

FAQs

Package last updated on 09 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc