In previous videos, you created a program called countdown. To make this program globally executable, you can add a bin option to the package.json file. Then, Alex runs npm link to add the command to the globally available list of commands. This can be run from any folder within the terminal. Running npm unlink removes from the list of global commands.
- [Instructor] So far within this lesson, … we've made a pretty cool countdown app using npm packages. … Let's make this package globally executable with a command. … Let's say whenever we type the word countdown … into the terminal, we want that to be a command … that will run our countdown clock. … So right now it's not, we can see bash, … countdown, command not found. … So in order to do this, the first thing … that we have to do is go into our countdown.js file, … and at the very top, we have to put a … #!/usr/bin/env node. … So this tells bash to use Node.js when executing this file, … so I'm going to go ahead and save that. … The next thing I need to do is I need … to go to my package.json, … and I need to add another field here called bin, … and within the bin I can specify the commands … that I want to use. … So we want the countdown command … to run our countdown.js file, … so I can go ahead and save this. … Now it's time to test the command to see if it works. … So we need to tell npm that this is a package …
- Making HTTP requests
- Building web and file servers
- Installing packages with npm
- Managing and linking global packages
- Working with Express, the web server framework
- Handling POST and DELETE requests
- Creating WebSockets
- Testing and debugging Node.js code
Skill Level Advanced
Node.js: Real-Time Web with Socket.IOwith Emmanuel Henri1h 24m Intermediate
Work with VSCode1m 59s
1. The HTTP Module
3. Web Servers
5. Node.js Testing
6. Automation and Deployment
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.