Node.js on SourceLair
Node.js is a first-class citizen in the supported stacks of SourceLair. This means that you can start developing your Node.js applications on SourceLair in seconds.
Node.js web applications
If you plan to work on a Node.js web application on SourceLair and start a project from scratch, it will work out of the box.
If you are creating a project by cloning an existing repo though, make sure to:
- Bind your server to
- Listen to the port exposed in the
PORTenvironment variable (see table below)
You can use any Node.js framework you wish to build your web applications.
Exposing your application to its Public URL
You should bind on the port defined in the
PORT environment variable, in order to be able to access your Node.js web applications via your project’s Public URL.
For convenience reasons though we always set the value of
PORT to 3000 for all Node.js projects.
Customizing how your web applications runs
To customize how your web application runs (e.g. set an explicit command to run your server or configure a worker process), make sure to:
- Learn about the available environment variables in your project
- Learn how to customize your server using a
SourceLair supports the latest Node.js LTS version, which right now is Node.js 10.
When a new Node.js minor version (e.g. 10.2) or bugfix (e.g. 10.2.1) release gets published, we will update all corresponding projects automatically (e.g. from 10.1 to 10.2).
Node.js projects in SourceLair ship with the latest
yarn preinstalled to let you install and manage Node.js libraries.
To install a Node.js library (e.g. React) in your SourceLair project, just run the following command in your terminal:
yarn add react
This will install React in your SourceLair project’s workspace, add React as a dependency in your
yarn.lock files to make sure you install the same libraries and library versions across your development and production systems.
You can also use
npm out of the box as well, but we recommend using
yarn instead as it is faster, more secure and more reliable.