I am currently developing nodejs app which will be hosted on iis, using iisnode.
I am having such a problem, this is part of my server.js:
app.listen(process.env.PORT);
process.env.PORT is passed by IIS, so at the moment when I locally building webpack package I have no port.
I deploy the build-ed package on my server, but looking at server.bundle.js, I can see:
app.listen(undefined);
now IIS can not start the application..
Is there any option to set webpack bundle-ed package to expect node process variable to be passed on the run?
Or maybe I am doing something wrong here?
This sounds like a job for the DefinePlugin
Related
Before, in the backend i would not use typescript, i would just use pure javascript, but know, this is my first backend app with typescript.
I want to deploy of course this app to heroku, but, i wonder if in the procfile component i have to tell heroku to get the server running in the server.ts, or in the server.js in the dist folder.
What i'm trying to say, is that, should i compile my code to translate it into pure javascript in the dist folder in order to deplot, or is it okay just to just run the server in the server.ts file ?
This is how my project looks like
TypeScript is ultimately just there to help you structure your code properly, as it is meant to be compiled to JavaScript. While you can run your server via ts-node on a VM, it is simpler to just compile it to JS and run it on your VM, as at that point it is no different from a typical NodeJS application. Other advantages are smaller build files since your js files will take up less space and startup time.
That being said there is no stopping you from using ts-node on heroku by putting ts-node index.ts inside your package.json start script, (also ts-node should be in dependencies not devDependencies), but personally I'd go down the compilation route as that is pretty much just another NodeJS application.
See Heroku can't find ts-node
I have a python application which I am deploying through Flask using the render_template() function onto a webpage. At the same time, I am trying to use npm to incorporate some javascript modules into my code. Whilst I have correctly installed the needed modules within the static folder with all my other javascript files, the code refuses to recognize these modules.
My Flask CLI shows that my local development server has correctly located the module file but if I run var module = require('module') the code shows no indication of having worked if run through the browser. This goes for whether I include this script inside my html template in the template folder, or an external javascript file in the static folder.
Interestingly enough, if I run the same external javascript file through the npm CLI using node script.js, the script will execute. Can someone explain what I'm doing wrong and why this is so? I'm completely new to node.js, npm and have just started today so any help would be appreciated.
I am currently basing my work off of the answer with 6 upvotes here: How can I serve NPM packages using Flask?
You can use electron as the ui for the python app by spawning your file and navigating to the local url in the app instead of using a browser. With this you will have some node capability.
Without knowing more, this is a bit of a stab in the dark, and quite late, however, I solved a similar problem with the following:
app = Flask(__name__,
static_folder = './public',
template_folder="./static")
npm is. Node.js packages manager tool. And it is only used node.js application.
If your application frontend is react or vue framework and your backend is node.js framework example Express or Koa, use npm is good. but now your backend is Flask
, you know Python package manage tools is Pip, so if you use Npm, you should use node in frontend , backend is flask, and frontend start npm start, backend start python app.py.
I have used vue-cli to scaffolding an vue app and now I want to setup a different web server rather then webpack-dev-server because I want a separate configuration file where I can configure the server like node express which I can use for production deployment.
Please suggest is there any way to configure the new server. Thanks
For development you should continue using webpack dev server (which is express).
For deployment you can use anything you want, just run:
npm run build
This will generate bundled javascript files, which you can then deploy anywhere.
I have a local development machine and a test server.
Now I have an APP_ID that's being used in Javascript. I've been looking into ways that they kan differ on my local machine and on the test server.
Using Gulp
With gulp it's possible to add a flag on the command line:
gulp build --env=production
That way I can get the correct APP_ID from a file.
The only issue is with this approach I need to run my build on the server, at this moment I run gulp locally and upload the changes to my server
Is it okay to build on the server? Are there other ways to use environment variables in Javascript?
My suggestion is to not build on the server but build locally and then deploy to the server using one of the many deploy solution (es. deployer.org for php). Normally javascript NPM packages put build output even in GIT repository ready for use in other projects or for deploy.
For more info on how to use env variable in node (gulp run over node) see this page
For example in linux you can set env variable with export
app.js :
console.log(console.log(process.env.foo))
Then try
> export foo=app1
> node app.js
Res:
app1
Then try
> export foo=app2
> node app.js
Res:
app2
This is valid only if you run your code server side on node (ex on gulp).
If you are developing a client side library and you want to create different builds that targets different enviroments you have to instruct gulp to do so. In this case this is a guide that can help you
I am working on a project for an embedded Linux system (busybox made with buildroot). I am wondering if it is possible to use node.js modules socket.io and express without having to install or run npm. The goal is to be able to have buildroot configured to create a busybox image that simply includes node.js, and then place all my javascript files in the proper directory and execute node app.js from the command line to run the node application (which will use socket.io and express).
So, for example on my development machine (That does have node.js and npm installed), I could run npm install socket.io so it would get socket.io and all its dependencies and install it in the node_modules directory of my project. If I place all those files in a directory and move them to the production environment (embedded Linux with just node.js installed and where npm install socket.io was never run) would my application work?
If I place all those files in a directory and move them to the production environment would my application work?
Yes, it would. However, if you do have any binary dependencies, they need to be recompiled, so it's a bit trickier. If you don't, you'll be fine.