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 version, along with any active LTS versions. When a new Node.js minor version (e.g. 9.3) or bugfix (e.g. 9.3.1) release gets published, we will update all corresponding projects automatically (e.g. from 9.2 to 9.3, but not from 8.9 to 9.3).
Setting the Node.js version of your project
You can set the Node.js version of your project when creating it by:
- Clicking on the Customize tab
- Choosing Node.js as the language of your choice
- Choosing the Version of your choice
- Creating your project
- Node.js 6 (6.12.2)
- Node.js 8 (8.9.3)
- Node.js 9 (9.3.0)
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.