npm module 'openurl' not working after deploying chatbot to Azure - node.js

I am working on chatbot development using node.js in MS bot framework.
I need to open a webpage during the conversation. I have used openurl npm module which is working successfully in local environment. After deploying to Azure from GitHub repository, the functionality is not working.
Could you please let me know any solution or fix for this?
I am also using other modules like system-sleep but I am facing the same problem. In short, all custom modules installed are not working after deployment to Azure.
var openurl = require('openurl');
var sleep = require('system-sleep');
openurl.open("https:google.com")
sleep(10);

While most modules are simply plain-text JavaScript files, some modules are platform-specific binary images. These modules are compiled at install time, usually by using Python and node-gyp Azure App Service does not support all native modules and might fail at compiling those with very specific prerequisites.
the description is from Using Node.js Modules with Azure applications.
Per my experience, the system-sleep module requires Python and node-gyp while installing.
You can try to install the modules in windows 32 platform on your local environment, and deploy your application to Azure with the node_modules folder which contains the compiled module.
On the other hand, you can leverage Azure App Service Editor to install those libs which are simply plain-text JavaScript files online.

Related

Creating Reactjs app production build without using node

We have just a single webpage with some links on clicking them it will redirect to different sources. As of now we are using "npm run build" to create the production package.
But because of the build files having dependencies with node, i cannot host it in a particular server.
Is there a way to create the Reactjs production build without using node ?
I suggest using Netlify to host your react app easily .
Below are some resources that can help you along the way.
https://www.netlify.com/with/react/
https://www.youtube.com/watch?v=sGBdp9r2GSg
You can have a build and upload it manually to your Netlify account,
You can use the CLI (netlify-cli) or you can your account to git .
Similar approach can be followed with git pages for example.
What packages do you have in your package.json file? Did you use a React project template that uses Node server-side features? It seems like you want to host your React project statically, not necessarily get rid of Node and npm.
For example, I've worked on lots of React projects using npm and create-react-app that we were able to host with a .NET backend and Microsoft IIS (instead of Node). The output is .html, .js, and other static files that you can host anywhere.
When you build a react app, the files at folder build contains everything it needs to run
If your hosting server hasn't integration with CI/CD, then you must deploy manually only the build folder, not the root folder (the folder that contains package.json).
I believe your issue is just a confusion/misunderstanding on how react works, how to deploy it, and how to run it.
React needs to be built on an environment where node, npm, and other tools are available. It can be on a build server or in your local machine.
After built, react app is just a folder with a bunch of html, css, js files which will run on the client browser, so, there's no dependency on NODE anymore.
These static files must be served with a simple static file server (apache, nginx, iis, etc),
I recommend you build the app locally on your machine and then deploy manually to your host through ftp, ssh or web interface.
If react is overkill to your needs, then don't use it.
The best approach is to host it in a cloud service that can do the full CI/CD integrated with git, all automated (Google GCP, AWS, Azure, Netlify, etc)

How to give different pip for google appengine to use while installing during gcloud app deploy python 3?

I want to deploy a flask application on Google standard appengine in python 3.7 runtime . I have a private dependency and want to connect to my personal feed for that. How to i ensure that the pip that GAE use is connected to my feed.
I checked the official docs of gcloud and found -
Dependencies
During deployment, App Engine uses the Python package manager pip to install dependencies defined in the requirements.txt metadata file located in your project's root directory. You do not need to upload dependencies as App Engine performs a fresh install.
Dependency specification using the Pipfile/Pipfile.lock standard is currently not supported and your project must not have these files present. in https://cloud.google.com/appengine/docs/standard/python3/runtime
If you are using App Engine Standard, you will not be able to do these kinds of specifications. My advice if you need to specify the pip for App Engine would be to use App Engine Flex in Custom Runtime and specify this on the Dockerfile.
You can find more information about this in the documentation for App Engine Custom Runtime and the Setup section section.
Hope you find this useful!

Why is Node.js required for Angular?

Why is Node.js required in order to use Angular?
In other posts, people say that it isn't required, and that it's only needed if you want server-side code. But the Angular documentation specifically states the need for Node.js in the "Getting Started" section. Why exactly is Node.js required? What if I want to use .NET Core as my server side back-end?
Straight from the Angular site:
Prerequisites before you begin, make sure your development environment
includes Node.js® and an npm package manager.
Node.js Angular requires Node.js version 8.x or 10.x.
To check your version, run node -v in a terminal/console window.
To get Node.js, go to nodejs.org.
Angular does not need Node.js directly and it is not mandatory to use Node.js. But you will need Node.js for all the build and development tools.
For an example these are few reasons that you need Node.js for building an Angular app,
npm (node package manager) comes with Node.js by default and it allows
you to manage your dependencies. So, you don’t have to worry for
operations like adding a dependency, removing some, updating your
package.json.
npm gives you angular cli or ng cli (angular command-line interface) which is a great tool for building your application easily
Node.js allows you to spin up a lightweight web server to host your application locally in your system.
You do need Node.js to develop Angular applications. All the tools you will run, while developing it, uses Node.js to run, like npm and the Angular CLI itself.
Node.js will serve your application on your machine. It has nothing to do with the server-side of your application, which can be any language you want.
Node.js allows you to spin up a lightweight web server to host your application locally in your system
NPM comes with node.js by default - used to manage dependencies
so you don't need to worry about adding/removing dependencies
(to node_modules folder, package.json/package.lock.json files)
NPM gives -> Angular CLI which is used to initialize,develop,scaffold & maintain angular application directly from command shell. It uses webpack for bundling your applications.
Also Angular uses TypeScript but browser understands Html & JavaScript only -> Typescript is transpiled into JS.
Angular CLI does all these behind the scene.

How to download Node.js project deployed on Google Cloud

I have deployed the Node.js code on Google Cloud using following command:-
gcloud app deploy
So, How to download Node.js project deployed on Google Cloud.
I'm not sure but if you need Tomcat server then set and deploy node.js application inside by creating a folder and add the dist folder files in it.
npm install --save #google-cloud/storage
At this point in time it is only possible to download your app's source code for Java, Python, PHP and Golang. The instructions are similar for Python, Golang and PHP:
appcfg.py -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] download_app [OUTPUT_DIR]
where:
[YOUR_PROJECT_ID] is your GCP project ID.
[YOUR_VERSION_ID] is the version ID of your application that you want to download.
[OUTPUT_DIR] is the full directory path to where you want your files downloaded.
In Java you use appcfg.sh:
appcfg.sh -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] download_app [OUTPUT_DIR]
See the link above and also the reference for Java and Python, PHP, Golang

How to package & deploy Node.js + express web application?

I am new to Node.js programming and I have recently created a sample working web application using (express, backbone & other complimentary view technologies, with mongoDB). Now i am at a point where I want to deploy the same on a staging environment and I am not sure how to package this application and distribute the same. [I can take care of mongoDb and setting it up seperately]
I am from Java world and in there we create jars for reusable libs and war/ear packages for web applications which is deployed in a servlet container. Now in this case since node.js itself acts as a web container as well, how do i package my webapp?
Is there any standard format/guidelines of packaging node webapps built using express? (Is there a similar jar/war packaging systems for node apps?)
How do I deploy it once packaged? Would it become an exe, since it is also its own container?
PS: As of now I am thinking of just manually copying all the required source files into the staging environment and run npm commands to download all dependencies on that machine and then use 'forever' or some other mechanism to run my server.js. (Also, add some sort of monitoring, just in case app crashes and forever fails) I am not sure if that is the right way? I am sure there must be some standardized way of addressing this problem.
Deploying Node.js applications is very easy stuff. In maven, there is pom.xml. Related concept in Node.js is package.json. You can state your dependencies on package.json. You can also do environmental setup on package.json. For example, in dev environment you can say that
I want to run unit tests.
but in production;
I want to skip unit tests.
You have local repositories for maven under .m2 folder. In Node.js, there is node_modules folder under your Node.js project. You can see module folders with its name.
Let's come to the grunt part of this answer. Grunt is a task manager for your frontend assets, html, javascript, css. For example, before deployment you can minify html, css, javascript even images. You can also put grunt task run functions in package.json.
If you want to look at a sample application, you can find an example blog application here. Check folder structure and package.json for reference.
For deployment, I suggest you heroku deployment for startup applciations. You can find howto here. This is simple git based deployment.
On project running part, simply set your environment NODE_ENV=development and node app.js. Here app.js is in your project.
Here is relative concept for java and nodejs;
maven clean install => npm install
.m2 folder => node_modules(Under project folder)
mvn test => npm test(test section on package.json)
junit, powermock, ... => mocha, node-unit, ...
Spring MVC => Express.JS
pom.xml => package.json
import package => require('module_name')
There is no standardized way, but you're on the right track. If your package.json is up to date and well kept, you can just copy/zip/clone your app directory to the production system, excluding the node_modules.
On your production system, run
npm install to install your dependencies, npm test if you have tests and finally NODE_ENV=production node server.js
Some recent slides I considered to be quite helpful that also include the topic of wrappers like forever, can be found here.
Hope this might be helpful for somebody looking for the solution,Packaging of Node js apps can be done using "npm pack" command.It creates a zip file of your application which can be run in production/staging environment.
Is there any standard format/guidelines of packaging node webapps
built using express? (Is there a similar jar/war packaging systems for
node apps?)
Yes, the CommonJS Packages specification:
This specification describes the CommonJS package format for
distributing CommonJS programs and libraries. A CommonJS package is a
cohesive wrapping of a collection of modules, code and other assets
into a single form. It provides the basis for convenient delivery,
installation and management of CommonJS components.
For your next question:
2. How do I deploy it once packaged? Would it become an exe, since it is also its own container?
I second Hüseyin's suggestion to deploy on Heroku for production. For development and staging I use Node-Appliance with VirtualBox and Amazon EC2, respectively:
This program takes a Debian machine built by build-debian-cloud or
Debian-VirtualBox-Appliance and turns it into a Node.js "appliance",
capable of running a Node application deployed via git.
Your webapp will not become an exe.
few ways to approach this:
Push your code into Git repository, excluding everything that isn't your code (node_modules/**), then pull it in your staging environment, run npm install to restore all dependencies
create an NPM package out of it , install it via npm in your staging environment (this should also take care of all of the dependencies)
manual copy/ssh files to your staging environment (this can be automated with Grunt), than restore your dependencies via npm
I used zeit's pkg module. It can create cross platform deliverables for linux/win/macos. Actually used it in production and works fine without any issues.
It takes in all the js scripts and packages it into a single file.
The reason I used it is because it helps in securing your source code. That way in production at customers environment they will have access to application but not the source code.
Also one of the advantages is that at production environment, you do not actually need to have the customer install node.js as the node binaries also get packaged inside the build.
https://www.npmjs.com/package/pkg

Resources