Before deploying Nodejs applications, there are several things that you must prepare, namely:
git@awan.io:TEAM/APP_NAME.git
After all of this is fulfilled, then you can start making applications based on a starter kit that can be cloned from https://github.com/awanio/nodejs-starter-kit
Noteworthy is that, Awan uses Yarn as a package manager. For that, make sure your application also uses Yarn as a package manager. More about Yarn can be seen here https://yarnpkg.com. But if you choose to use npm, it can be added in the web.package_manager
section with the value npm
. For the yarn package manager, make sure the yarn.lock
file is also committed. And for the npm package manager, make sure the package-lock.json
file is commited.
Then, Awanio uses Node version 10 as the runtime to run the application. For that, please match the application you are about to make.
version: '1.0'
web:
type: nodejs
version: 10
run: node index.js
Here's an example if using npm
as a package manager:
version: '1.0'
web:
type: nodejs
version: 10
run: node index.js
package_manager: npm
Create an index.js file that contains:
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(process.env.PORT || 3000, function () {
console.log('Example app listening on port 3000!')
})
Your application also requires a package.json file. Here is an example of the contents:
{
"name": "awan-node",
"version": "1.0.0",
"description": "simple awan node web app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"node",
"js"
],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.1"
}
}
Run the following command to install the required packages:
yarn install
After the process is complete, run the application locally. For that, run the command:
node index.js
Please check the application in the browser with the address: http://localhost:3000
After the application is ready, add git remote Awanio to the project:
git remote add awan git@awan.io:TEAM/APP_NAME.git
Now commit and push to the git server to Awanio
git push awan master
After the deployment is complete, please check your application at https://app-name.diawan.id
Generally Nodejs based applications require a build process before the application is run in production. To handle this need, here is an example of a awan.yml file that can be used during deployment.
version: '1.0'
web:
type: nodejs
version: 10
run: yarn start
script:
postinstall:
- yarn build