https://github.com/liby99/nodejs_server
https://github.com/liby99/nodejs_server
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/liby99/nodejs_server
- Owner: Liby99
- Created: 2016-01-12T22:45:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-06T22:47:23.000Z (over 9 years ago)
- Last Synced: 2025-01-21T10:51:04.918Z (4 months ago)
- Language: JavaScript
- Size: 756 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nodejs_Server
A self-written Node.js Server Application.
# Introduction
Note: The Application is written integrating the file structure. So do not change the name of server files or path names.
To Start running the server after installed node.js, open terminal, go to /server directory, and run:
$ node index.js
Then you will see a logServer now running on port 8080
To change the port, go to /server/data/config.js
And change the port entry to the port you want.To connect to your mysql database, also go to /server/data/config.js
And change the correspondingmysql_username
mysql_password
mysql_database
So that you will successfully connect to your database# Samples
There are several samples in the published files:
The front end files:
/index.html
/css/basic.css
/js/basic.jsThe back end files:
/handler/comment.js
/server/module/comment.js
/server/module/user.js
Hope you can know how to use the server application through these files.# Note for Get/Post AJAX Requests
From the client Javascript, you need to request the url:
/ajax/[target]?action=[data]
Where the [target] should not contain any extension names. (And [data] follows the original structure.)
Containingaction
is easy for the handler to recognize what thing it needs to do.# Paths
/
Store .html pages.
/css
Store .css stylesheets. Could be accessed by anyone
/js
Store client .js scripts. Could be accessed by anyone
/img
Store basic images
/fonts
Store fonts
/handler
Store handler for get/post requests. Couldn't be accessed by client.
/server
The Place storing server scripts. Couldn't be accessed by client.
/server/index.js
The main server script to be run by
$ node index.js
Distributes the request to corresponding part of handling
/server/file.js
If the request is for certain files, the request will be distributed here.
Will read the code config so that the user will get 403 Forbidden for requesting forbidden files.
If there's no such files, the user will get 404 Not Found.
/server/ajax.js
The script that handles the ajax get/post requests. Distribute the requests to ~/handler directory.
/server/request.js
The script encapsulates the method for getting post body data.
Note: Should be able to discriminate malevolence post.
/server/response.js
The script encapsulates the method for standardizing response data, including error_code, error_log, content
/server/mysql.js
The script encapsulates the methods for making connection to mysql database (reading the config files),
query and execute
/server/data/
Stores data files, including the path authentication, http port, mysql connection config, and http return type.
/server/data/path.js
If the entry gets value 0, it means that this path could be accessed by client
Otherwise cannot.
/server/module/
The place storing encapsulated object-oriented classes.
/server/node_modules/
The place storing npm (nodejs package manager) installed libraries.