Just yesterday, Ali Churcher shared a neat way to make a resume using a CSS Grid layout. Let’s build off that a bit by creating a template that we can spin up whenever we want using the command line. The cool thing about that is that you’ll be able to run it with just one command.
I know the command line can be intimidating, and yes, we’ll be working in Node.js a bit. We’ll keep things broken out into small steps to make it easier to follow along.
Like many projects, there’s a little setup involved. Start by creating an empty folder in your working directory and initialize a project using npm or Yarn.
mkdir your-project && cd "$_" ## npm npm init ## Yarn yarn init
Whatever name you use for “your-project” will be the name of your package in the npm registry.
The next step is to create an entry file for the application, which is index.js in this case. We also need a place to store data, so create another file called data.json. You can open those up from the command line once you create them:
touch index.js && touch data.json
Creating the command line interface
The big benefit we get from creating this app is that it gives us a semi-visual way to create a resume directly in the command line. We need a couple of things to get that going:
- The object to store the data
- An interactive command line interface (which we’ll build using the Inquirer.js)
Let’s start with that first one. Crack open data.json and add the following:
{ "Education": [ "Some info", "Less important info", "Etc, etc." ], "Experience": [ "Some info", "Less important info", "Etc, etc." ], "Contact": [ "A way to contact you" ] }
This is just an example that defines the objects and keys that will be used for each step in the interface. You can totally modify it to suit your own needs.
That’s the first thing we needed. The second thing is the interactive interface. Inquirer.js will handle 90% of it., Feel free to read more about this package, cause you can build more advanced interfaces as you get more familiar with the ins and outs of it.
yarn add inquirer chalk
What’s that chalk thing? It’s a library that’s going to help us customize our terminal output by adding some color and styling for a better experience.
Now let’s open up index.js and paste the following code:
#!/usr/bin/env node "use strict"; const inquirer = require("inquirer"); const chalk = require("chalk"); const data = require("./data.json"); // add response color const response = chalk.bold.blue; const resumeOptions = { type: "list", name: "resumeOptions", message: "What do you want to know", choices: [...Object.keys(data), "Exit"] }; function showResume() { console.log("Hello, this is my resume"); handleResume(); } function handleResume() { inquirer.prompt(resumeOptions).then(answer => { if (answer.resumeOptions == "Exit") return; const options = data[`${answer.resumeOptions}`] if (options) { console.log(response(new inquirer.Separator())); options.forEach(info => { console.log(response("| => " info)); }); console.log(response(new inquirer.Separator())); } inquirer .prompt({ type: "list", name: "exitBack", message: "Go back or Exit?", choices: ["Back", "Exit"] }).then(choice => { if (choice.exitBack == "Back") { handleResume(); } else { return; } }); }).catch(err => console.log('Ooops,', err)) } showResume();
Zoikes! That’s a big chunk of code. Let’s tear it down a bit to explain what’s going on.
At the top of the file, we are importing all of the necessary things needed to run the app and set the color styles using the chalk library. If you are interested more about colors and customization, check out chalk documentation because you can get pretty creative with things.
const inquirer = require("inquirer"); const chalk = require("chalk"); const data = require("./data.json"); // add response color const response = chalk.bold.blue;
Next thing that code is doing is creating our list of resume options. Those are what will be displayed after we type our command in terminal. We’re calling it resumeOptions so we know exactly what it does.
const resumeOptions = { type: "list", name: "resumeOptions", message: "What do you want to know", choices: [...Object.keys(data), "Exit"] };
We are mostly interested in the choices field because it makes up the keys from our data object while providing us a way to “Exit” the app if we need to.
After that, we create the function showResume(), which will be our main function that runs right after launching. It shows sorta welcome message and runs our handleResume() function.
function showResume() { console.log("Hello, this is my resume"); handleResume(); }
OK, now for the big one: the handleResume() function. The first part is a conditional check to make sure we haven’t exited the app and to display the registered options from our data object if all is good. In other words, if the chosen option is Exit, we quit the program. Otherwise, we fetch the list of options that are available for us under the chosen key.
So, once the app has confirmed that we are not exiting, we get answer.resumeOptions which, as you may have guessed, spits out the list of sections we defined in the data.json file. The ones we defined were Education, Experience, and Contact.
That brings us to the Inquirer.js stuff. It might be easiest if we list those pieces:
Did you notice that new inquirer.Separator() function in the options output? That’s a feature of Inquirer.js that provides a visual separator between content to break things up a bit and make the interface a little easier to read.
Alright, we are showing the list of options! Now we need to let a a way to go back to the previous screen. To do so, we create another inquirer.prompt in which we’ll pass a new object, but this time with only two options: Exit and Back. It will return us the promise with answers we’ll need to handle. If the chosen option will be Back, we run handleResume() meaning we open our main screen with the options again; if we choose Exit, we quit the function.
Lastly, we will add the catch statement to catch any possible errors. Good practice. :)
Publishing to npm
Congrats! Try running node index.js and you should be able to test the app.
That’s great and all, but it’d be nicer to make it run without having to be in the working directly each time. This is much more straightforward than the functions we just looked at.
- Register an account at npmjs.com if you don’t have one.
- Add a user to your CLI by running npm adduser.
- Provide the username and password you used to register the npm account.
- Go to package.json and add following lines:
"bin": { "your-package-name": "./index.js" }
- Add a README.md file that will show up on the app’s npm page.
- Publish the package.
npm publish --access=public
Anytime you update the package, you can push those to npm. Read more about npm versioning here.
npm version patch // 1.0.1 npm version minor // 1.1.0 npm version major // 2.0.0
And to push the updates to npm:
npm publish
Resume magic!
That’s it! Now you can experience the magic of typing npx your-package-name into the command line and creating your resume right there. By the way, npx is the way to run commands without installing them locally to your machine. It’s available for you automatically, if you’ve got npm installed.
This is just a simple terminal app, but understanding the logic behind the scenes will let you create amazing things and this is your first step on your way to it.
Source Code
Happy coding!
The above is the detailed content of How to Build Your Resume on npm. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.

To deal with CSS browser compatibility and prefix issues, you need to understand the differences in browser support and use vendor prefixes reasonably. 1. Understand common problems such as Flexbox and Grid support, position:sticky invalid, and animation performance is different; 2. Check CanIuse confirmation feature support status; 3. Correctly use -webkit-, -moz-, -ms-, -o- and other manufacturer prefixes; 4. It is recommended to use Autoprefixer to automatically add prefixes; 5. Install PostCSS and configure browserslist to specify the target browser; 6. Automatically handle compatibility during construction; 7. Modernizr detection features can be used for old projects; 8. No need to pursue consistency of all browsers,

Setting the style of links you have visited can improve the user experience, especially in content-intensive websites to help users navigate better. 1. Use CSS's: visited pseudo-class to define the style of the visited link, such as color changes; 2. Note that the browser only allows modification of some attributes due to privacy restrictions; 3. The color selection should be coordinated with the overall style to avoid abruptness; 4. The mobile terminal may not display this effect, and it is recommended to combine it with other visual prompts such as icon auxiliary logos.

Use the clip-path attribute of CSS to crop elements into custom shapes, such as triangles, circular notches, polygons, etc., without relying on pictures or SVGs. Its advantages include: 1. Supports a variety of basic shapes such as circle, ellipse, polygon, etc.; 2. Responsive adjustment and adaptable to mobile terminals; 3. Easy to animation, and can be combined with hover or JavaScript to achieve dynamic effects; 4. It does not affect the layout flow, and only crops the display area. Common usages are such as circular clip-path:circle (50pxatcenter) and triangle clip-path:polygon (50%0%, 100 0%, 0 0%). Notice

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizontalpadding/margins—idealforinlinetextstyling

TheCSSPaintingAPIenablesdynamicimagegenerationinCSSusingJavaScript.1.DeveloperscreateaPaintWorkletclasswithapaint()method.2.TheyregisteritviaregisterPaint().3.ThecustompaintfunctionisthenusedinCSSpropertieslikebackground-image.Thisallowsfordynamicvis

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

CSS,orCascadingStyleSheets,isthepartofwebdevelopmentthatcontrolsawebpage’svisualappearance,includingcolors,fonts,spacing,andlayout.Theterm“cascading”referstohowstylesareprioritized;forexample,inlinestylesoverrideexternalstyles,andspecificselectorslik
