NearlyFreeSpeech.net (NFSN) is a very inexpensive web host, DNS provider and domain registrar. NFSN added support in 2014 for NodeJS, Django, and tons of other languages through persistent processes. This guide, based on the Django tutorial provided by NFSN, will demonstrate the setup I used for creating a node.js daemon.
If you’re creating a new website, select the Custom domain type:
If you have an exisiting website, the domain can by changed to Custom:
- Select your domain under Sites
- Go to the Config Information section and on click the Edit button on Server Type
- Select the Custom domain type:
Next, use SSH to setup your node service on NFSN’S server. Your username, password, and SSH hostname can be found in your site’s information:
- Connect to your server with SSH. See this section to set up a SSH key on NFSN.
> ssh email@example.com firstname.lastname@example.org's password: [mycustomdomain /home/public]$
- Go into the
/home/protectedfolder to set up your node website. This will allow
node.jsto run as the
[mycustomdomain /home/public]$ cd /home/protected
- Upload or clone your node.js code into this folder. In this example, I'm going to use the node-js-sample repository.
[mycustomdomain /home/protected]$ git clone https://github.com/heroku/node-js-sample.git [mycustomdomain /home/protected]$ cd node-js-sample
npmdependencies for your project
[mycustomdomain /home/protected/node-js-sample]$ npm install
run.shscript for running your node process. A NFSN daemon is given a file to run. This file will encapsulate the
npm run startcommand and any other setup your process needs. See environment variable setup in the Additional Details if your project requires environment variables.
[mycustomdomain /home/protected/node-js-sample]$ nano run.shIn
run.sh, type the command that starts your node.js process:
npm run start
<Enter>to save and exit from
- Test running your startup script:
[mycustomdomain /home/protected/node-js-sample]$ chmod +x run.sh [mycustomdomain /home/protected/node-js-sample]$ ./run.sh > email@example.com start /home/protected/node-js-sample > node index.js Node app is running at localhost:5000
Make sure your node.js service works from
run.sh before continuing to the next step. Press
X to kill your service on SSH before the next section.
Note: It’s okay if your node app runs at a high-level port like
10080. NFSN doesn’t give root permissions to allow for low-level port access, but instead uses Proxies to give your server access to low level ports. See Configure Proxy later in the guide.
Configure NearlyFreeSpeech.net Daemon
- Select your domain under Sites
- Go to the Daemons section and on click the Add a Daemon button
- Change configuration:
Tag: nodeNote: This tag is used to locate logs for your process
Run Daemon As:
- Click the Add Daemon button
Go back to your site configuration
Go to the Proxies section and on click the Add a Proxy button
5000Note: Change to your node port if different
☑ Bypass Apache Entirely(Checked)
Click the Add Proxy button
Check your work! Go to your domain to see if your daemon and proxy are working.
If you website isn’t working yet, you can use SSH to consult your process’s logs. Output from the daemon process is stored in
mycustomdomain /home/protected/node-js-sample]$ cd /home/logs [mycustomdomain /home/logs]$ ls daemon_node.log [mycustomdomain /home/logs]$ tail -f daemon_node.log > firstname.lastname@example.org start /home/protected/node-js-sample > node index.js Node app is running at localhost:5000
To restart your daemon process, go to your site’s configuration and click Stop on your daemon:
Afterward, click Start on your daemon to start it again:
Set up an SSH key on NearlyFreeSpeech.net
Setting up an SSH key isn’t difficult, but uses the NFSN web interface instead of the filesystem. See NearlyFreeSpeech.net’s reasoning here.
Go the Profile tab
Click Add SSH Key in the sidebar
Paste your key into the input box, and click Add SSH Key
Setting environment variables on NearlyFreeSpeech.net Daemon
NFSN doesn’t have a environment variable editor like heroku or other cloud services, but environment variables can easily be set in the
run.sh script file.
For example, if my node process required the
NZ (timezone) environment variables set, my
run.sh script would look like this:
PORT="8080" AUTH_KEY="XXX_XXXXXXXXXX" NZ="America/Denver" npm run start