Skip to content

Instantly share code, notes, and snippets.

@nrl240
Last active March 8, 2021 14:48
Show Gist options
  • Save nrl240/181245dec7e58e811fba17e1a769c76f to your computer and use it in GitHub Desktop.
Save nrl240/181245dec7e58e811fba17e1a769c76f to your computer and use it in GitHub Desktop.
Exit Ticket: Day 5 - Node

Exit Ticket: Day 5 - Node

You should be able to:

  • Explain the purpose of Node
  • Use module.exports and require to create modular applications
  • Describe what npm is and its purpose
  • Explain asynchronicity in JavaScript (its "non-blocking" nature)

In your own words, what is Node? And why do we need it?

  • Node is a runtime environment that has the ability to run a V8 engine on environments other than the browser (e.g. operating systems, servers, etc.).

What does module.exports do?

  • It's an object that tells Node which pieces of code to export from a given file so that other files are able to access the exported code.

What does require do?

  • It's a built-in function that allows a file to include modules that exist in separate files. The basic functionality of require is that it reads a JavaScript file, executes the file, and then proceeds to return the exports object.

Which of the following is not a built-in Node module?

What is the order of output of this snippet of code:

console.log('Hello')
setTimeout(() => { console.log('a new') }, 5000)
console.log('World') 
Log 1st 2nd 3rd
Hello ☑️
a new ☑️
World ☑️

What is the output of the following snippet of code:

const cool = () => {
  console.log('Running inside the cool function')
  setTimeout(
    () => {
      console.log('Timing out inside the cool function')
    },
    3000
  )
}

setTimeout(
  () => {
    console.log('I am not in any function')
  },
  3000
)

cool()
console.log('End of File')
Log 1st 2nd 3rd 4th
Running inside the cool function ☑️
Timing out inside the cool function ☑️
I am not in any function ☑️
End of File ☑️
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment