0

I have created a node application using typescript.

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.ts",
  "author": "",
  "license": "MIT",
  "scripts": {
    "start": "node -r ts-node/register index.ts",
  },
  "dependencies": {
    "@types/express": "^4.17.3",
  },
  "devDependencies": {
    "ts-node": "^7.0.1",
    "typescript": "^3.4.5"
  }
}

Currently, I have used following docker file for running my application

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 1234
CMD ["npm", "run", "start"]

I want to run my application using node command instead of npm

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 1234
CMD ["node", "-r", "ts-node/register", "index.ts"]

But it throws an error like this

'egister", "index.ts"]' is not recognized as an internal or external command,
operable program or batch file

1 Answer 1

2

The ts-node is not registered in the WORKDIR environment, you need to add the relative path.


CMD ["node", "-r", "./node_modules/ts-node/register", "index.ts"]

If you want to run other packages, you need to register the path like this

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
Sign up to request clarification or add additional context in comments.

Comments

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.