I just started with nodejs and since I can't reference the app.js to the html file since I'm actually starting that js file with the nodejs. Is there a way to achieve this?
It doesn't work like that. I think you are trying to use the app.js file of a node app as if it was a simple script reference in the html with the tags.
NodeJS runs in the server and the HTML file runs in the client. The server script you are running can provide data to the client, client-server must be "connected" with an API.
If you are using vue or react for the Front-End, check Axios as a library for fetching data via API.
Check this tutorial
It's a detailed and great explanation for what you need.
Related
I want to use React for a project I am working on, but I also want to use an API.
How can I do it?
I have tried to Google this and ask different people, but I have not got a response yet, so I thought I would ask here. I want to use express and maybe not use create-react-app (as it takes up a lot of storage).
Working on a custom server doesen't preclude the use of an API.
If you want fetch the API from the express server and inject it directly on react frontend you need to enable server side rendering (useful post) and pass the data collected as a props from the server (check this example).
Rather then you can build your react project (using even create-react-app) and build an express server who return the index.html on call.
Personally I prefer the first one solution.
I have tried going through log4js but do we need to create an api to store logs in log4js.
If you're comfortable with Javascript, the simplest solution would probably be to write a little Node web server (using Express, for instance) that you could send errors to when they happen? The server could append them to a file as it receives them.
Having some trouble understanding where to put html files and redirect. I'm very new to react and node js and just getting started with my first project. I have authentication working well, where my App.js in my client side has some inputs and it sends that info to node js server, which authenticates.
After authentication, should I send back a response to react so react can load a new web page? Or do I simply redirect to an html file on the server side? (res.sendFile...)?
Thanks
From my personal experience. You only use nodejs actually expressjs to read database, design api and expose api endpoint to the front end. On react part, you could call the api and also setup the proxy in the package.json file. Good example to follow:https://create-react-app.dev/docs/proxying-api-requests-in-development/
You could use it as reference.
I am using Node JS as web API server, for the front end, I am using Angular 4, Android and IOS. I have successfully implemented file upload using post request. I am exposing only one port outside. I need to implement file upload with a progress bar. I have only worked with POST and GET requests in past.I am not getting how to implement it on the server and send the progress responses to the front end. Additionally is there any other method that can be used.
It would be of great help if someone could help me with this process
For file upload you can use DropzoneJS. Since you are using Angular for front end use Dropzone for Angular.
I was looking into it and heard socket.io can be used to achieve the same. i need to user sharp package on the streamed data
For the server side, I use the built in express routers using multer. Multer parses multipart form data and uses callbacks that play very nicely with express routers.
Then for the UI you need an element that can upload multipart form data. If your using HTML 5 then you should be able to use just about any library that is out there. I personally use Vaadin uploads. It's a nice drop in element that does all the work for you. It even has a nice upload bar and status built in.
I have been working on React.js for a month now. I have been using Webpack dev server which is a node.js Express server and enables us to render react.js on browser. I want to know whether using React.js will limit us on using only a node.js http server or is there a way we can use a simple http server as well with React.js.
I have also been wondering whether it is useful to use React.js for developing webpages that have mostly pre-fixed contents text fields, data etc. during request/response for any API operation.
Does using React.js limits us on using a node.js server
No. React is predominantly a client side library. It doesn't care how it is served to the client.
In the end you are just writing JavaScript. You can deliver the JavaScript code to the client whichever way you want.
It depends. Generally the answer is no. If you only want to use it as a client-side library, it doesn't matter what the web server is. But actually, react components can also be rendered on server side so you can develop universal/isomorphic apps. In that case you will need a node.js server.
Take a look at this universal example.
we are using php+yii2+react +redux+es6 without node.js server, but ngnix. At the end it is just javascript, so that we use gulp + babelify to translate es6 to es5 and then php yii2 application renders basic container to which react application renders himself.
Node.js is one of the options, you can use wathever server you want, just need something like gulp or webpack to compile your js and all dependencies to the ready to use standalone js.