Today we rolled out NodeJS and NPM to all containers on our WordPress Hosting, ticking off another item from our most requested feature list. As this is an entirely new feature, it should be considered beta.
Please note that support will be limited while our systems and WordPress teams gain experience with the feature and we can only offer limited support if an npm command fails for some reason.
Express Server, the NodeJS HTTP server, is strictly disabled as Nginx is already bound to port 80 and 443. Our installation of NodeJS is intended for background tasks only such as running Gulp/Webpack on the server.
What is NodeJS?
It’s often requested by developers on our WordPress Hosting because tools like Webpack and Gulp use the language. These tools automate a lot of frontend tasks from minification of code to SASS compilation amongst others. Modern frontend development is often driven by these tools and until now you would have had to do all that before uploading to your container. Now you can run these tools on the container itself.
Node Package Manager is a popular package management tool for distributing NodeJS code. Its closest equivalent in the WordPress world is the “wp-cli install plugin” option. NPM allows you to install packages locally to the project (just that directory) or globally for use across the container (please note this is currently disabled; packages can only be installed locally). NPM is the primary way to get things like Webpack and Gulp working.
This is beta, is it going away?
We hope not! We will be monitoring usage carefully for abuse and its effect on container resources. It’s unlikely to be removed but we may tweak and change settings. When we plan changes we will let people know in advance.
As is the default in NodeJS, no logging is configured. If you are using something like Winston, which is a logging module, then you shoiuld set the path to /var/www/vhosts/yourdomain/statistics/logs/ as this is writeable and a good place to store logs.
I don’t use NodeJS or Webpack – should I?
To be clear you don’t have to change your workflow. If you never make use of NodeJS your container will behave in exactly the same way as it has been up to now. Unlike PHP-FPM or MariaDB, when not doing anything NodeJS takes up no resources and by default it doesn’t run any lasting processes. If you want to experiment then you are of course welcome to do so!
How do I get started?
It’s all set up ready for you, so simply SSH in and run “npm init” in the folder you wish to start using NodeJS to create your package.json file and off you go!
NodeJS is a powerful language capable of doing great harm even when running as an unprivileged shell user in exactly the same way as PHP. It’s also worth remembering that unlike the WordPress repo for plugins, NPM packages have not had any security checks so it’s up to you to check the package and its dependencies.
Unlike WordPress plugins, we won’t be able to automatically update your packages so you are responsible for any updates that are needed. We recommend you regularly update your packages and their dependencies.
Containers are monitored for high CPU and memory usage but it’s also worth you keeping an eye on your container to make sure you don’t have stray NodeJS processes running for prolonged periods.
Whilst we already know someone is going to ask for Express Server and for us to open ports for web sockets, both are currently on the “I’m afraid not” list. If you have any other requests or ideas – not just for NodeJS but WordPress Hosting in general – we would love to hear them. Our WordPress Hosting has changed dramatically over the last couple of years with feedback from our clients and we are always looking for new ideas.