In our previous post, we create a profanity filter in NodeJS but the one thing we did not do was add any automated tests. I am huge fan of automated testing so in this article we are going to use Jest to add some automated tests to our profanity filter.
I was recently working with a client on a Q&A submission form for student assemblies that they are running and the client needed to strip out any profanity from the question submission.
We decided that we want this in the API versus on the submission form itself so that the students couldn’t just open up the browser developer tools and figure out how to skirt around the filter. The API is written in NodeJS Express.
Downloading and extracting a zip file using Node seemed like a pretty easy task but alas it took some time to figure out.
While researching how to do this, I didn’t find a library that had all of the requirements within it but I did find a few that allowed me to meet the requirements
Step 1 was to get the zip file downloaded using Node and make sure that I could manually open it. To download the zip file, I am using the superagent package and piping the download to a file using fs.
I am sure that many of you are in the same situation that I am in with needing a different version of node for different projects and you don’t want to have to create a new virtual machine for each project just because of node. Luckily with nvm you can install multiple versions of Node on the same machine and switch between them with a simple command line call.
The one downside to having multiple versions of Node installed is that you have to install the global packages for each version of node that you want them available to. There is no ability to share packages between versions. This means that it will take a bit more disk space but most node packages are fairly small so this should be a none issue.
I ran into an issue with an npm package mis-behaving in Visual Studio 2015 but working just fine from the command line.
After scratching my head for awhile trying to figure out what was going on, I discovered that Visual Studio was pointing to its own version of npm and node and not that ones that were available in my path that the command line was using. Visual Studio 2015 ships with:
When you are using npm, bower, and git behind a proxy server you have to do a little bit of configuration. Luckily it is super easy to do these configurations. Almost all of the programs have command line commands to set and unset the proxy server.
set http_proxy=[Your Proxy]:[Proxy Port]
set https_proxy=[Your Proxy]:[Proxy Port]
set http_proxy=
set https_proxy=
Run from an administrative command prompt