Github project address

The project is simple and concise, and all the basic functions are realized, which is suitable for beginners

Function application

  • Express based development
  • Token Login Authentication
  • Used by database module Sequelize
  • Windows Server IIS deployment

Project introduction

1. Express based development

The Express framework is incredibly powerful and can save a lot of things. Make development easier, don’t you know? Express 4.X

2. Use the Token to authenticate

After each request header carries the token more usage can be viewed in the usage documentation

Token authentication

    // Get token data
    let token = req.headers['access-token'];
    / / token authentication
    jwt.verify(token, constant.jwtsecret, (err, decoded) => {
            if (err) {
               ...
            } else {
                req.decoded = decoded;
                next();// Proceed to the next route}})Copy the code

3. Use Sql framework Sequelize

The Sequelize framework is designed for mysql, SQLite, Postgres, and SQL (Microsoft Database)

Database configuration Connection

const sequelize = new Sequelize('Database'.'Username'.'password', {
    host: 'localhost'.// Database address
    dialect: 'mssql'./ / database types' mysql '|' sqlite '|' postgres' | 'MSSQL'
    // Pool configuration for database connection pools
    pool: {
        max: 5.idle: 30000.acquire: 60000,},define: {
        timestamps: false.// schema: "dbo"}});// Test the database link
sequelize.authenticate().then(function () {
    console.log("Database connection successful");
}).catch(function (err) {
    // Print output when database connection fails
    console.error(err);
    throw err;
});
Copy the code

The database uses PS. I only listed the basic operation, the specific operation can see the code implementation, code annotation is clear

Create User user.create (value) Queries the first qualified User user.findone (options) updates User information user.update (value, options) Deletes User user.destroy (options)Copy the code

3. Deploy Windows Server and IIS

If the server is not running Windows Server, forget about it. The web.config file in the root directory is for the file that deploys the project in IIS. Deployment Process

feedback


If there is an error in the code, or if there is anything unclear, please reply to: [email protected] or [email protected]

If you think it helps, give it a thumbs up!