Skip to content

Run sass-convert in a node express service #24

@andersonbalves

Description

@andersonbalves

Hi guys!

Is there a way to run this lib in a express service?

I have to do a service to convert css codes to sass codes.
I tried do make this but when I call the convert({from: 'css', to: 'sass'}) I get this following error:

events.js:187
      throw er; // Unhandled 'error' event
      ^
Error: spawn sass-convert ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn sass-convert',
  path: 'sass-convert',
  spawnargs: [ '--from=css', '--to=sass', '--stdin', '--no-cache' ]
}

My code:

app.post(["/v1/css-to-sass/"], (req, res) => {
   var inputStreamReq;

   req.pipe(req.busboy);
   req.busboy.on('file', function (fieldname, file, filename) {
     console.log("Uploading: " + filename);
     const name = uuidv1();
     inputStreamReq = fs.createWriteStream(__dirname + '/../model/' + name + '.css');
     file.pipe(inputStreamReq);

     inputStreamReq.on('close', () => {
       vfs.src(__dirname + '/../model/' + name + '.css')
         .pipe(converter({
           from: 'css',
           to: 'sass'
         }))
         .pipe(vfs.src(__dirname + '/../model/'));

       res.send('');

     });
   });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions