I've never been much of an OS/Platform purist. For as long as I can remember I have switched between Unix/Windows based systems on a regular basis for various reasons. With that said, I develop primarily on a Windows machine, and most of my projects end up running on a Linux server (Node modules), or on a Linux kernel (Android) of some sort, so being familiar with the *nix school of thought is quite helpful in the long run.
Without getting too thick in my personal examples of what it's like living between platforms, I'd instead like to share some of the stuff I've written or tools I use to make my life a bit easier.
This post explicitly covers a script I wrote and added to my Current User, Current Host - console PowerShell Profile to make initializing new Node.js modules much easier and specific to my preferences.
If you'd like, you can skip straight to the code on GitHub if that's more your style, or read on for my explanation of my problem and my solution.
Well, it wasn't a problem so much as a nuisance. When creating a new Node module, my standard workflow was something like so:
- Open Visual Studio Code
- Go to File -> Open Folder
- Navigate to my Node.js modules folder -> Create a folder for the module
- Open the newly created folder and launch the integrated terminal
npm initto setup the
package.jsonwith my default values
touch index.js; code index.jsto create the new file and start work
To say this is a bit tedious and annoying would be an understatement.
I created a PowerShell Script called
New-NodeModule.ps1, with a single function
New-NodeModule, that I dot-source in my
Profile.ps1. The function does the most common things I do when creating a new module, such as create a
package.json with the default values for the license, author info, and so forth.
The only required information to create a new module is the name of the module, which is accepted as the first parameter or using a named parameter like
New-NodeModule -ModuleName outside-cli. If desired, you can set the location for the module to be stored using the
-ModulePath parameter. Moreover, regarding the accepted parameters, I prefer to open the newly created module in Visual Studio Code right after creating it so there's a
-OpenInVSCode parameter that defaults to
$true but can be set to
$false to prevent opening the newly created module.
When creating a new Node module, I tend to use a lot of the same settings. For example, I always use Jest for testing purposes and all of my projects are formatted/linted with StandardJS. More specifically:
- As I'm creating the module, I can rest assured that I'm the author, so I'll always have the author block filled with information about myself
- I always have the
startscript as a simple
- I mentioned I test with Jest, so my
testscript will always start with
- I prefer my projects to be licensed under the MIT License as it most aligns with my views on OSS
For more specifics, refer to the source code itself as it's all right there. 🤓
To conclude, the last significant change I made to make it easier to use this new file was to add aliases to the
New-NodeModule function (
newnpm). Now, whenever I want to create a new module, I simply type
newmod in my terminal and it does what I need 😊
If you have any questions, comments, or concerns, please feel free to contact me directly or comment on the post!
Posted on May 25 '18 by: