Node Js with Azure WebApp using VSCODE - node.js

Recently i have deployed a node.js server side app with budo and it works fine.. but after deploying to Azure(WebAPP) it is not working and throws error that 'require' is not defined. I have used VSCode to develop the project

After some research, I found that the bodu which is a browserify development server. So it looks like your app is in client-side JavaScript but the node.js app is in server-site, they are technically different. And require() does not exist in the browser/client-side JavaScript, so it raised your issue.
To fix this issue please try using a modular script loader like browserify to traverse all your sources and concatenate all required files into the bundle then including bundle.js in your HTML file. Finally, redeploy it and you will get it worked.
Any further concern or if I have any misunderstanding, please feel free to let me know.

Related

Express JS in Altassian Forge causing "process.cwd is not a function" error

I am new to development on Jira Cloud and am currently exploring creating apps using the Atlassian Forge. I was trying to use Express JS in the code as a middleware. Turns out that during deployment, it keeps giving this error "process.cwd is not a function."
The error received while deploying the app.
I tried installing process module (via npm i process; which was successfully done) and updating the webpack version but none of it worked.
Can someone please tell what could be causing this error?
If possible please suggest the alternative for using Express JS in Altassian Forge?
Thanks in advance.
Apoorva
From the documentation:
When a Forge app is invoked, the JavaScript code is executed within the app sandbox. This environment differs from a traditional Node.js environment you might already be familiar with.
You'll need to write your functions in a subset of Node.js. Some globals are not exposed, for example:
process (except for process.env)
queueMicrotask
which means that some NPM packages that depend on these may not function correctly.
If Express JS depends on process.cwd(), that would explain the error. You may be able to work around this if it depends on it in theory but not in practice:
If process.cwd() is only used in test cases or example code, you can delete it or make sure it's not bundled.
If it is used, but using a dummy string like "/" would work, you could stub out the call using DefinePlugin or similar.

Openlayers node module only works with client side rendering. Why?

I initialized a brand new Next.js project and installed the official openlayers module (https://github.com/openlayers/openlayers) with npm in it.
But as soon as I import it in one of the src js files, I get some error like this: Unexpected token 'export'
The only way I got it working is by telling Next.js to not use that src file on the server side.
I understand that it only wants to work with client side rendering.
Can anyone explain to me, why is it only working like that?
What is different in this module that prevents it from using it with the default ssr settings?
OpenLayers got full node.js support since I posted my question, so with that it become obsolete.
Find more about it on their GitHub repo.

Does the default Reactjs application use node.js?

This may be a dumb question, but is the default react app (created using npm create-react-app my-app) using node.js? I am confused because in my web development class at university, I had to download node.js to create react applications. However, I didn't have to do anything like creating a server or initiating a node.js file, which is described in w3school's node.js tutorial. Because of this, I found out that I don't even really know what node is used for, besides downloading packages like redux and whatnot.
create-react-app uses node.js for all of its dev tooling. Likewise, a lot of the tools you'll use in the React ecosystem (like webpack, prettier, npm), all run on top of node.js as well).
You'll most probably build your react app to a static file, in which case the production output will not require node.js, it will be html and javascript assets that can be served directly to a client.
Hope that helps! Let me know if you have other specific questions
Node.js is used for server-side while React.js is for the front-end part. So, no, you don't need Node.js.
Under development mode, yes. Create react app runs NodeJs with Webpack Dev Server to allow you get feedback when modifing files, start or stop the server.

AngularJS app have different behavior locally and on Heroku

I have written an app using the MEAN-stack(MongoDB, Express, AngularJS Node.js). Locally everything works as its supposed to but for some reason it behaves differently when I run it on Heroku.
The problem is that some of my angular controllers are transferred with the content type header text/html instead of application/javascript. As stated this is not a problem locally.
I have updated my npm and bower packages so everything should be up to date. Except for express where I use v. 3.4.4(because version 4.x.x requires a rewrite of the config). I use the same version of the frame works locally and on heroku.
Please let me know if I can provide any more information that would make it easier to solve the problem.
Regards
In most of the cases, when your scripts are transferred as text/html, it's because they are not found and return an HTML 404 page, you can check it using the Chrome Developer Tools in the Network tab.
When you have this issue, there is a lot of chance that your app is completely broken and that's why I ask you this.
Don't know if you're using some tasks runner like Grunt for your deployment process or just pushing your project as is but in both cases you need to check that the path of your files are correctly set by checking the requested url of yours scripts transferred with the wrong MIME TYPE.
Had also same problem with the Yeoman generator that was messing with the minification and file renaming some time ago.

Using Require.js with Trigger.io

I just started using Trigger.io and am building a movie mobile app using backbone.js and require.js but without much success.
My project scaffold is generated by Grunt-BBB.
It runs fine when it's built and run as a web app ("forge build web", & then "forge run web"), but unfortunately, it fails to load the JS files when it's built and run as iOS or Android. I've looked through the demo Backbone.js example, but it's not using Require.js.
I realize that Require.js is async in nature and that might be the root cause of it not working when running on the mobile.
Any alternative to Require.js or work-around to get Require.js working with Trigger.io will be appreciated! Thanks!
I just had a go with Require.js in a Trigger.io app and it seems to be working fine on both iOS and Android. I don't have an app setup with Grunt-BBB so I haven't tested that.
When running on Android you should see any Javascript errors that occur in the log output, do you see any, and if so are they at all helpful?
Otherwise if you could zip up the src folder of the app you are trying to build and send it to support#trigger.io we can take a more detailed look at what is going wrong.

Resources