I have seen lot of videos and posts configuring project with npm (Node.js). I already have .Net server where I want to use React.JS and Redux.
I could set it up for React by adding following JS file downloaded.
<script src="~/Scripts/src/react.min.js"></script>
<script src="~/Scripts/src/react-dom.min.js"></script>
<script src="~/Scripts/src/browser.min.js"></script>
But how to include Redux in my application to use React with Redux?
Related
I'm new to back-end coding, and I'm struggling to understand exactly what a "fullstack" app would look like.
Is it:
A Node-Express server that serves index.html, which has <script src="main.jsx"></script> in it (If this is the case, how would the .jsx content get compiled into browser-ready javascript?)
A Node-Express server that serves some data (.json) + a frontend app (that you would initialize with Vite or CRA) that fetches from said server?
Both are currect , your server can serve content to the cliend (first case) or send data to the client (json , xml or etc).
Note that when you are working with react and .jsx component you have to build your project and server the html file (including js , css) via express server
Using NodeJS, is it possible to listen to calls from localhost:3000 to my.site.com/resources/* and serve those files locally instead ?
Context: my Angular app relies on resources from a CDN. Sometimes when the CDN is down, I want to serve these files locally.
You can use javascript to check if angular object is correctly loaded , if not you generate a new tag a local link instead of CDN
<script src="//cdn_link/angular.min.js"></script>
<script>
(typeof angular != 'undefined') || document.write('<script src="local_link/angular.min.js")<\/script>')
</script>
For angular2 you can check for ng object instead of angular
I am working on nodejs express app. I want to include google polymer ui components in my express app.I tried a lot about integrating polymer in express app. I found no solution for this. Is there any way to integrate polymer ui component in express app ?
I used polymer webcomponents to create a node express server found on this: express-web-components
His tutorial shows how to use webcomponents to create a server, but you can clearly adopt that to your usecase and use ui components like the server ones. Note: To use the server-side web components, the ScramEngine offers access to the runtime.
Basically it is:
Include polymer and your component like so:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/express-web-components/express-app.html">
Use your component for example like so.
<express-app port="1234">
<express-middleware>
</express-middleware>
</express-app>
This is only for Polymer 2. Version 3 will be different from the import side.
I 'm a beginner of Node.js development,
Now I try to use bootstrap framework in my first Express web app.
I use
npm install bootstrap
to download the files,and it seems that npm puts them in my node_modules folder.
My question is how can I refer to the bootstrap files in my views in express?
I know a typical way is copying the bootstrap file into the public folder. So my html files can find them. But I don't think this is a good idea.
Thank you.
You need to use in your server.js:
app.use(express.static(__dirname + '/node_modules/bootstrap/dist'));
to define a static resourse and then use:
<script language="javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
I found a similar question. In which the solution is explained better by #augusto-goncalves. His solution works for me. It is similar to the solution of #victor-behar but more elaborated and clears confusion.
You have to reference it in the <script> and <link> tags in the header or at the bottom of your main script.
If you're using express, you're probably using templating. To use it in your header part or in your main template (depending on how you've managed your views) like :
<script language="javascript" src="node_modules/bootstrap/.../bootstrap.min.js"></script>
and
<link rel="stylesheet" href="node_modules/bootstrap/.../bootstrap.min.css"/>
This works only if you didn't moved your files with a gulp or a grunt task
There's also a way to transpile scss in express using node sass middleware, for example https://github.com/sass/node-sass-middleware.
That way you can override bootstrap scss. You can do the same for JS with webpack: transpile client-side js and then include the bundle.js in your frontend.
I have a single page application with node serving up the backbone app along with all the marketing material. I would like to serve all assets (JS, html, images) from our Rackspace Cloudfiles CDN to reduce load times as gzip files will be delivered as well as reduce the load on my node server.
What is the best way to automate this?
I need would need to:
sync files after build to the CDN
reference the CDN for all static assets in production mode
I found solutions with both Grunt and Node Modules which are used in my project.
Grunt CDN
Grunt Cloud Files
Node Asset Rack
If I go with Grunt - which is my first choice,
How do I set the express application I am running on to serve from the CDN in production?
Is it better to use the asset manager for node since its serving all my assets anyway?
How do I set the express application I am running on to serve from the CDN in production?
When you render your view you could pass it a flag to tell where to pick the assets from.
I've got an example here if you are interested. In my case I've got a flag on whether I am connected to the network or not (e.g. during a flight) to decide where to pick my JS files from:
<% if(isConnected) { %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-cookies.min.js"></script>
<% } else { %>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/angular.min.js"></script>
<script src="/js/angular-resource.min.js"></script>
<script src="/js/angular-cookies.min.js"></script>
<% } %>
https://github.com/hectorcorrea/hectorcorrea.com/blob/master/views/index.ejs#L136
In my example, the value is hard coded, but you could easily pass Express dev/prod value to the view to get the same thing done automatically.