cmd: serve
[contents]

Contents

Syntax

The syntax for the serve command is:

nift serve (sleep-sec)
nsm serve (sleep-sec)

Description

The serve command is for serving a project locally (automatically building updates to the project without having to manually run a build command), it either takes zero paremters and sleeps for 0.3s between running incremental builds, or takes a single floating point parameter which should be the number of seconds to sleep between running incremental builds.

Note: If your updates are not appearing upon refresh or reload of the output file there's a chance the builds are failing, try checking the .serve-build-log.txt file in the project root directory.

On linux you can also run nsm serve -s & to serve in the background then to stop serving run killall nsm. Then you can open the webpages/output files in the output directory and Nift will automatically build the project in the background, picking up any changes, just reload your browser window or reload the output file in your editor (often they will pop up a dialogue saying the file has been changed and asking whether you would like to reload).

If you would like your website to be served at an IP address, eg. if you are using Nift on a server or a virtual machine, try using Python (there are also options available through npm). Run either of the following in the project root directory for a url similar to 0.0.0.0:8000/site and from the site directory for a url similar to 0.0.0.0:8000.

python3 -m http.server 8000
python -m SimpleHTTPServer

If you want live reloading for a website check out Live Server which you can get from npm, or Live Reload. In either case you can add them to pre/post serve scripts for your website so that it is all integrated in to the Nift serve command and requires no manual effort on your part.

Example

Example of serve being used:

nift serve
nsm serve 1.5

Sponsors