Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Vent Display
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcos Mendez Quintero
Vent Display
Commits
6e33ccf9
Commit
6e33ccf9
authored
4 years ago
by
Ben Coombs
Browse files
Options
Downloads
Patches
Plain Diff
Using express
parent
986110e0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.js
+12
-20
12 additions, 20 deletions
server.js
with
12 additions
and
20 deletions
server.js
+
12
−
20
View file @
6e33ccf9
var
http
=
require
(
'
http
'
);
// Import Node.js core module
//var http = require('http'); // Import Node.js core module
var
express
=
require
(
'
express
'
);
var
app
=
express
();
const
SerialPort
=
require
(
'
serialport
'
);
//https://serialport.io/docs/guide-usage
const
Readline
=
require
(
'
@serialport/parser-readline
'
);
...
...
@@ -18,27 +20,17 @@ parser.on('data', data =>{
console
.
log
(
data
);
});
var
server
=
http
.
createServer
(
function
(
req
,
res
)
{
//create web server
if
(
req
.
url
==
'
/
'
)
{
//check the URL of the current request
port
.
write
(
'
testing testing hello ben
\n
'
,
(
err
)
=>
{
app
.
get
(
'
/
'
,
function
(
req
,
res
)
{
res
.
send
(
'
Hello world
'
);
port
.
write
(
'
testing testing hello ben
\n
'
,
(
err
)
=>
{
if
(
err
)
{
return
console
.
log
(
'
Error on write:
'
,
err
.
message
);
}
});
// set response header
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
text/html
'
});
// set response content
res
.
write
(
'
<html><body><p>Sending message via serial!</p></body></html>
'
);
res
.
end
();
}
else
res
.
end
(
'
Invalid Request!
'
);
});
server
.
listen
(
5000
);
//6 - listen for any incoming requests
})
console
.
log
(
'
Node.js web server at port 5000 is running..
'
)
\ No newline at end of file
var
server
=
app
.
listen
(
5000
,
function
()
{
var
host
=
server
.
address
().
address
;
var
port
=
server
.
address
().
port
;
console
.
log
(
"
Node.js server running on port %s
"
,
port
);
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment