Install Nodejs On Windows/Mac/Linux download from the below website url. https://nodejs.org/en/download/ Install Nodejs on ubuntu curl -f...
Install Nodejs
On Windows/Mac/Linux download from the below website url.
https://nodejs.org/en/download/
Install Nodejs on ubuntu
curl -fsSL https://deb.nodesource.com/setup_17.x | bash -
apt-get install -y nodejs
Step 1:- Install Visual Studio Code on your system.
Step2:- Create a folder say C:\nodeapp and open it in visual studio code
cd c:\nodeapp
code .
Step3:- Create a index.js file and write below code in this file
const app = express()
const port = 8080
app.get('/', (req, res) => {
res.send('This is my first Node application!')
})
app.listen(port, () => {
console.log(`Application is listening at http://localhost:${port}`)
})
Step 4: Create package.json file and write below content
{
"dependencies": {
"express": "^4.16.1"
}
}
Step5: Run below commands in the terminal
npm install
node index.js
Step6: Add below yml file to run the application in build and deploy stage. Create artifacts in .gitlab-ci.yml
stages:
- build
- deploy
build:
stage: build
script:
- apt update -y
- apt install npm -y
- npm install
artifacts:
paths:
- node_modules
- package-lock.json
# expire_in: 1 week
deploy:
stage: deploy
script:
- apt update -y
- apt install nodejs -y
- node index.js > /dev/null 2>&1 &
Run node application on Gitlab using docker image
stages:
- build
- deploy
build:
image: node
stage: build
script:
# - apt update -y
# - apt install npm -y
- npm install
artifacts:
paths:
- node_modules
- package-lock.json
# expire_in: 1 week
deploy:
image: node
stage: deploy
script:
# - apt update -y
# - apt install nodejs -y
- node index.js > /dev/null 2>&1 &
COMMENTS