I am trying to link a js (the js is a local file in the project) to this html (results.html) :
The problem is that the js is not loading .
I have try with :
/static/js/ResultspieChart.js
../static/js/ResultspieChart.js
static/js/ResultspieChart.js
But if I use:
<script th:src="#{/js/ResultspieChart.js}"></script>
it works , th is a Java template engine
In fact the url according to intelliJ helper is well formed,where is the problem ?
The file system paths are not resolved correctly most of the times. Use an http server to serve your html and ../static/js/ResultpieChart.js should work. You can use http-server npm package as below (Prerequisite: You should have node installed):
1. Install http-server globally
npm install -g http-server
Start the http-server in the root of your project
http-server
This will start a server at default port (8080). So if you browse localhost:8080, you can see your files
Related
I want to test my react/ node.js web app with a production build. I already run npm run build at the app directory and created build folder.
I was unable to run the application using localhost:8080 (server port).
Are there any ways to double check if the application is actually running in that port or access production-ready application?
PS. I used serve to host the application but it posts error 404: The requested path could not be found
Thank you for your help.
Every SPA application has its own package.json file. Inside you have to see the script section:
Normally after you run nm run build you have a compiled version of your code.
At this point, you have a see the dist folder.
After this, you can either run npm run start and you have to see
(this option is not suitable for SSR frameworks like NUXT or NEXT)
or if you don't have that option install an npm package that renders your compiled code by doing the following:
npm install -g serve
serve -s build
and you have to see
I am currently working on a website project using javascript. I am unable to call the socket.io module, which I installed using npm install socket.io.
I tried to use it in the HTML script:
<script src="/socket.io/socket.io.js"></script>
But I got an error, apparently because the module is not found.
I didn't find any other way to install it on the internet. Does anyone know a way to avoid this problem?
When you do npm install socket.io, the socked.io library is installed to a special directory called node_modules.
In your HTML file, you are trying to load the library from a path that expects it to be located in a subdirectory called socket.io in the public documents directory of your server.
You have three options:
copy the socket.io library to a directory where your server can serve it and the browser can find it
adjust the path in your script tag to point to node_modules/socket.io
load socket.io from a CDN, for example:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
I would recommend the third option.
You can install it globally using -g parameter:
npm install -g socket.io
If you don't want to do the above then you need to run the project using local node_modules dependencies. To do that:
Add the following alias in ~/.bashrc alias npm-exec='PATH=$(npm bin):$PATH'
Run all npm commands by prefixing npm-exec to use local node modules
Example: npm-exec npm build
Here is my app structure
I am trying to run simple backbone app which i downloaded from one site from nodeJS ,I wasn't able to do so this is my first attempt in starting a backbone app standalone
If you want to serve the files you can install http-server with
npm install -g http-server in your command line. Then go to the directory and type http-server it should run the files on a certain loop address with a port number
When I run npm install -g <package> it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.
What can I do to fix this?
Thanks
I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm; to the user variable(since %AppData% dir is depending on user) PATH to fix it.
You will need to log out then log back in for the change to your PATH variable to take effect.
SET PATH=%AppData%\npm;%PATH%
You have to run this line SET PATH=pathtonodejs;%PATH% (where pathtonodejs is where you installed nodejs) once the installation for nodejs is complete and it should work.
It turned the problem was a change in behavior of the module I was using.
I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path
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.