Skip to content

Instantly share code, notes, and snippets.

@aconanlai
Created June 27, 2019 01:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aconanlai/42492364aa036a02d10aec0a22415ec6 to your computer and use it in GitHub Desktop.
Save aconanlai/42492364aa036a02d10aec0a22415ec6 to your computer and use it in GitHub Desktop.
node on nearlyfreespeech
Since mopsled didn't renew their domain, this is from their original blogpost which was a useful reference:
https://web.archive.org/web/20180220190550/http://www.mopsled.com/2015/run-nodejs-on-nearlyfreespeechnet/
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.
NFSN Configuration
If you’re creating a new website, select the Custom domain type:
Choose custom domain option for new site
If you have an exisiting website, the domain can by changed to Custom:
Select your domain under Sites Site selection
Go to the Config Information section and on click the Edit button on Server Type Config information
Select the Custom domain type: Choose custom domain
Project Setup
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:
SSH information
Connect to your server with SSH. See this section to set up a SSH key on NFSN.
> ssh mopsled_mycustomdomain@ssh.phx.nearlyfreespeech.net
mopsled_mycustomdomain@ssh.phx.nearlyfreespeech.net's password:
[mycustomdomain /home/public]$
Go into the /home/protected folder to set up your node website. This will allow node.js to run as the web user.
[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
Install npm dependencies for your project
[mycustomdomain /home/protected/node-js-sample]$ npm install
Create run.sh script for running your node process. A NFSN daemon is given a file to run. This file will encapsulate the npm run start command 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.sh
In run.sh, type the command that starts your node.js process:
npm run start
<CTRL>+X, Y, <Enter> to save and exit from nano.
Test running your startup script:
[mycustomdomain /home/protected/node-js-sample]$ chmod +x run.sh
[mycustomdomain /home/protected/node-js-sample]$ ./run.sh
> node-js-sample@0.2.0 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 CTRL+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 5000, 8080, or 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 Site selection
Go to the Daemons section and on click the Add a Daemon button Add a daemon button
Change configuration:
Tag: node Note: This tag is used to locate logs for your process
Command Line: /home/protected/<NODE_FOLDER>/run.sh
Working Directory: /home/protected/<NODE_FOLDER>
Run Daemon As: web
Daemon configuration
Click the Add Daemon button
Configure Proxy
Go back to your site configuration
Go to the Proxies section and on click the Add a Proxy button Add a proxy button
Configure proxy:
Protocol: http
Base URI: /
Document Root: /
Target Port: 5000 Note: Change to your node port if different
Direct: ☑ 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment