I need to use axios both on my client and my server. I import it as
clientside: <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
serverside: npm install
and it is fine.
The question: is there a way to import both from one source? (like you can import socket.io client as
<script src="/socket.io/socket.io.js"></script>
from installed sources)
axios is just an example. Can relate to anything used on cli and serv.
CodePudding user response:
Well. Yes. If you've installed axios from npm then you'll have a axios.min.js file on your hard disk.
You just need to do something to give it a URL. The specifics of that will depend on your HTTP server. You might use an Alias directive if you were using Apache HTTPD or the static middleware if you were using Express.js.
You can't really compare to Socket.io though. The Socket.io module that is used server-side sets up a bunch of end points (because the socket communication takes place over HTTP) and one of those end points is designed to serve up the client-side code.