How to develop a new IoTAgent - node.js

I'm developing a new IoT Agent according to https://iotagent-node-lib.readthedocs.io/en/latest/howto/index.html
and I'm trying to run the following code: node index.js
but a warning shows up: (node:6176) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
DEP0097 - Deprecation Warning (NODE.JS)
Any suggestions how to solve it?
thank you!

It appears that you are running your IoT Agent under Node 14. The Domain API has been deprecated and this is the cause of your warning. There is code within the IoT Agent Node lib currently uses the Domain API for communications with Telefonica Steelskin.
The IoT Agents are tested against LTS node releases, (currently 10 and 12 see here) and Node 14 doesn't hit LTS until October 2020, so I would expect an interim release should fix the issue.
In the meantime if you run your agent under an earlier version of Node - for example via Docker. An example can be found in the Custom IoT Agent tutorial Dockerfile
ARG NODE_VERSION=10.17.0-slim
FROM node:${NODE_VERSION}
COPY . /opt/iotXML/
WORKDIR /opt/iotXML
RUN \
apt-get update && \
apt-get install -y git && \
npm install pm2#3.2.2 -g && \
echo "INFO: npm install --production..." && \
npm install --production && \
# Remove Git and clean apt cache
apt-get clean && \
apt-get remove -y git && \
apt-get -y autoremove && \
chmod +x docker/entrypoint.sh
USER node
ENV NODE_ENV=production
# Expose 4041 for NORTH PORT, 7896 for HTTP PORT
EXPOSE ${IOTA_NORTH_PORT:-4041} ${IOTA_HTTP_PORT:-7896}
ENTRYPOINT ["docker/entrypoint.sh"]
CMD ["-- ", "config.js"]
The node version can be altered by adding NODE_VERSION to the Docker build command when building the Docker container.

The problem has to do with docker for windows toolbox. I installed linux and the custom iot agent worked. I think the problem ocurred because of the environment variables. For some reason windows 10 doesn't initiate .env archive variables that exist in the project.

Related

Jenkins Agent Dockerfile and dynamic node version

I have a Jenkins NodeJs Agent that currently installs node 14. That node version is hard coded in the Dockerfile
RUN export \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& source "$NVM_DIR/nvm.sh" \
&& nvm install 14.21.1 \
&& nvm use 14.21.1 \
...
I want to be able to install any version of node that is specified by the Agent user.
&& nvm install NODE_VERSION \
So far, I think it can be done by adding an .nvmrc file to a project and specifying the version.
How does the Agent dockerfile access the value in the .nvrmc file?
I've seen withEnv and ARG mentioned, but I don't know if this is
what I need.
Or is there a way to keep that Agent dockerfile backward compatible,
so that the Agent users can still use Node v14 while others can use a later Node version?

ERROR in Module.createRequire is not a function

I tried to create react app with node version 12.1.0 but it warned me that my minimum node version should be at least 14.0. I used nvm to change my node version to 14.0 and created react app.
However, I want to use my app on node version 12.1.0. So I changed to node version v12.1.0 but I got:
"ERROR in Module.createRequire is not a function" error. Also " ERROR
in Error: Child compilation failed: Module.createRequire is not a
function "
As we can read in official docs:
Create React App
Create React App is a comfortable environment for learning React, and
is the best way to start building a new single-page application in
React.
It sets up your development environment so that you can use the latest
JavaScript features, provides a nice developer experience, and
optimizes your app for production. You’ll need to have Node >= 14.0.0
and npm >= 5.6 on your machine.
So these are requirements that you must meet and it seems that it cannot be avoided that way .
Use 14+ of node.js version
just use nvm -version_name
Try completely updating the newest, stable version of both nodejs and npm:
sudo apt -y update && sudo apt -y upgrade
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt -y update && sudo apt -y upgrade
sudo apt -y autoremove
Then, change directories into your app directory:
cd myapp/ #Change this to match your app directory
Remove node_modules folder
sudo rm -rf node_modules/
Then reinstall the packages:
npm i
See if your app builds successfully:
npm run build
I got this error with an app created with create-react-app v5.0.0, when I was using node v16 (via nvm). Downgrading the project to node 14.18.12 fixed the issue for me (I also deleted node_modules and ran npm install again).
I encountered this while using Eslint.
Upon running, npm run lint, the error appeared.
I have various Node versions on my dev machine and I noticed that I had run the command using v10.
When I switched to v16, the command worked.
Cause of the error:
Using incompatible Node versions.
Solution
Change Node.js versions (I use Node Version Manager - nvm to do this).
Now node 19.x is released and the 18.x is the recommended version
if you want to upgrade your node version, simply you can change this line
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
to
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
and
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
for latest version
You can try
curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install -y nodejs
https://github.com/nodesource/distributions/blob/master/README.md#debinstall

How to install Node.js version 16.x.x in a Debian based image (Dockerfile)? (why so hard?)

Date: Tuesday October 5th, 2021
Node 10.x was released on 2018-04-24 (but that's the default version when using apt-get)
I have needs to have both Python and Node.js installed in running container. I can get the latest version of python in a container using:
FROM python:alpine
or
FROM python:buster <== Debian based
How do I get the latest version of node.js (16.10.0) installed on Debian (in a Docker container)
Whe I do this:
FROM python:buster
RUN apt-get update && \
apt-get install -y \
nodejs npm
I get these versions of node:
node: 10.24.0
npm 5.8.0
and when run in the container give a long statement about no longer being unsupported.
What's up with the package repo that 'apt-get' pulls from, that it will not install later versions of node (14.x or greater)?
If I pull from:
FROM python:alpine
and include these lines
RUN apk -v --no-cache --update add \
nodejs-current npm
I will get node 16.x version, which makes it easy. I don't have to do anything else.
Is there something equivalent for python:buster (Debian based)
I would really like a one or two liner in my Dockerfile and not a pages of instructions with a dozen commands to simply get node in the image.
I would appreciate any tested/proven reply. I am sure a number of others have the same question. Other stackoverflow articles on this subject are convoluted and do not provide the simple solution I am hoping to find that is available with pytyon:alpine
There is a reason I need python:debian and cannot use python:alpine in this one use case, otherwise I would chose the latter.
Is there a way some how to get a package repo maintainers attention to show me how to get a recent version (14..16), into the apt-get repository?
It appears many people are having issues with this.
You can use:
FROM python:buster
RUN apt-get update && \
apt-get install -y \
nodejs npm
RUN curl -fsSL https://deb.nodesource.com/setup_current.x | bash - && \
apt-get install -y nodejs

Azure functions - there is chance to install packages via apt-get?

My azure functions needs some linux package to work, but i cant install them by apt-get, because i get error "sudo command not found" or "(Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied).
So my question is: There is any chance to install these packages without sudo?
Im using Bash in Azure App Service(kudu)
You can build and run your Azure Functions from a custom container. This way you can also install other packages.
This sample project does pretty much exactly that.
FROM mcr.microsoft.com/azure-functions/node:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
# Install FFMPEG
RUN apt-get update && \
apt-get install -y ffmpeg
RUN cd /home/site/wwwroot && \
npm install
Source

Combine docker files. thrift and nodejs

I'm a web dev and I use node. A colleague has added code to my branch that uses the thrift npm package. Although thrift is a npm package, it needs to be installed on the local machine still for the package to be used. I do not have apache thrift installed and cannot run the code. I will eventually have to deploy this code so I'd like to look into creating a docker container that has thrift available and the nodejs code can run in that container using the thrift installation.
I cannot find a container for this purpose. There is an official docker image with the thrift library, but that seems like it only runs thrift files. there is also an the node container of course, any way I can combine the two?
Check this docker file which contains both nodejs and thrift. I directly build this image from appache/thift which is official docker image of thrift and install nodejs and npm.
FROM apache/thrift
RUN apt-get update && apt-get install -y --no-install-recommends curl sudo
RUN curl --silent --location https://deb.nodesource.com/setup_8.x | sudo bash - && \
apt-get install --yes nodejs && \
apt-get install --yes build-essential
RUN apt-get install --yes npm
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/bin/bash"]
Build command:
docker build -t thrift-node .
Run command
docker run --name test-thrift - -p 3000:3000 --rm -it thrift-node
Verify version command
thrift -version
nodejs -v
npm -v

Resources