0

I've just started programming in Node.js and in Azure DevOps. I've tried to run a simple Node.js example to see how things work in Azure DevOps, but I've encountered an error and I don't know how to get past it. I have this file imported from Github (File1.js):

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log('Server running at http://${hostname}:${port}/');
});

And in my azure-pipelines.yml I have the following code:

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript

pool:
  vmImage: 'Ubuntu 16.04'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '11.x'
  displayName: 'Install Node.js'

- task: Npm@1
  displayName: 'npm install'
  inputs:
    command: install

- script: npm compile 'File1.js'

I know the last line from the .yml file generates an error, but I don't know how to make the connection to the .js file in order to run it. If I take out that line, everything works fine, but... it doesn't run the file... Please help with any solutions/hints. They will be very much appreciated! Thank you!

2
  • you are not supposed to run it on the build agent, just compile it and package and deploy to the target server\paas offering Commented Dec 7, 2018 at 8:30
  • @4c74356b41 Can you please help me a little? I'm new to this and don't know how to do this... Commented Dec 7, 2018 at 8:33

1 Answer 1

2

I'm not a node expert, unfortunately, so I dont really understand what you are trying to do, but in general the workflow is as this:

  1. commit code
  2. build start, runs compile\tests. packages everything into an archive or a package of some sort
  3. release starts to push build results to the server that will run the code and serve the clients.

I have a sample pipeline for nodejs.

pool:
  vmImage: 'Ubuntu 16.04'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '8.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build
  displayName: 'npm install and build'

- script: |
    zip -r result.zip . -x .git/**\* > /dev/null
  displayName: 'package results'

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.SourcesDirectory)/result.zip' 
    artifactName: 'drop' 
  displayName: 'upload artifacts'
Sign up to request clarification or add additional context in comments.

2 Comments

Do you have to do something special for the versioning? Azure DevOps keeps telling me there's no version.
you should raise a new question, mate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.