0

My IP address is 192.168.1.6 OS : Windows 7 Working directory : c:\ArduinoJs My node.js file is located in C:\ArduinoJS folder named as serialtoJSON.js listen (8080) My index.html file is located at c:\ArduinoJS , the same place where node.js file is located.

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://192.168.1.6:8080/socket.io/socket.io.js"></script>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <script src='https://swww.tokbox.com/v1.1/js/TB.min.js'></script>
    <script type="text/javascript" src="http://static.pureexample.com/js/flot/jquery.flot.min.js"></script>
$(function() {
        // open a connection to the serial server:
        var socket = io.connect('http://192.168.1.6:8080');

This is working fine. But I want to keep the .js files in C:\ArduinoJS\js and load from them. Hence I changed the above script to

<script src="js/jquery-1.8.3.js"></script>

But this is giving 404 error. How can I load .js files like jquery-1.8.3.js ,TB.min.js etc from my own computer.

2

1 Answer 1

0

Use express to serve files from a directory.
For the following example:
create a new sub-directory where you got (your starting point) serialtoJSON.js named client

var express = require('express');       
var app = require('express')();     
var http = require('http').Server(app);
var io = require('socket.io')(http);    
var path = require('path');         

app.use(express.static(__dirname + '/client')); //Store the index and js here
http.listen(8080, function(){ console.log('[+] Server listening @ :8080');});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.