Skip to main content

How to Create a Simple Website With Node.js/Docusaurus

Prerequisites:
In this tutorial, we assume you have set up a running VM instance and already installed and set up Apache

In this tutorial, you will learn how to use node.js to build a website from scratch using a template. We will use Docusaurus, which is a tool which uses React, a JavaScript library to build a website from scratch. Most of the files are automatically generated and the process takes little time to set up. The templates available in the Docusaurus toolset is tailored for documentation writing, and can be easily written using Markdown. The website you are currently reading is created using Docusaurus. A lot of the content in this guide is based on this fast track guide.

Step 0: Install Node.js

note

The steps for setting up this website can either be done directly on the VM or you could do it locally on the computer which you want to do development on

You can find various instructions on how to install Node.js in this GitHub repository.

For Debian, first make sure you are logged into an account with sudo rights and are located at the root level. Then, we will first verify that we have curl installed:

sudo apt-get install -y curl

Then, run

sudo curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh

Run the setup script:

sudo shell nodesource_setup.sh

Then, install Node.js:

sudo apt-get install -y nodejs

Verify the installation:

node -v

Step 1: Install and run docusaurus

Before starting this step, it might be a good idea to change to a user on your UNIX VM which does not have sudo rights.

We will install docusaurs and also create a website called "my-website" in our home directory (denoted by a tilde-symbol, "~").

cd ~
npx create-docusaurus@latest my-website

go through the install wizard.

then cd into my-website and run

npx docusaurus start

You can also alternatively run

npm run start

for the same output.

note

Don't want to build Docusaurus from scratch?

If you already have the docusaurus files available (for example after cloning them from a repo), you still need to run npm install before executing npm run start to run the website.

The website generated by docusaurus is now run on port 3000. You can check what is being generated by running:

curl localhost:3000

Which now should look like: alt text

note

Killing a process

If a process is already running on port 3000, you can identify it using sudo lsof -i :3000, then after identiyfing the PID, you can end the processes using sudo kill <PID>