3

How can I translate var exec = require('child_process').exec; to ES6? I know the following: import exec from 'child_process';

What I don't know is how to add the .exec at the end to the ES6 syntax.

1
  • 1
    Try import { exec } from 'child_process' Commented Feb 10, 2018 at 18:55

1 Answer 1

7

How can I translate var exec = require('child_process').exec; to ES6?

You do:

import { exec } from 'child_process';

I know the following: import exec from 'child_process';

That's actually wrong, it is as I've done above. More on import here.

Otherwise, is simply:

import child_process from 'child_process';
const exec = child_process.exec;

You CANNOT do anything like:

import exec from 'child_process'.exec;
Sign up to request clarification or add additional context in comments.

2 Comments

The curly bracket format in import statements is not destructuring, calling it that is misleading. It is its own entirely separate syntax, since you do { exec as myExec }, not { exec: myExec }.
@loganfsmyth: I've updated my answer with the correction

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.